Jupyter notebook安装R内核和简单实例

通过Anaconda安装R内核

conda install -c r r-essentials

同时运行R和Python

安装rpy2conda install rpy2 or pip install rpy2
创建python内核的notebook:

In [1]: %load_ext rpy2.ipython
In [2]: %R require(ggplot2)
Out[2]: array([1], dtype=int32)
In [3]: import pandas as pd
        df = pd.DataFrame({
                'Letter': ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c'],
                'X': [4, 3, 5, 2, 1, 7, 7, 5, 9],
                'Y': [0, 4, 3, 6, 7, 10, 11, 9, 13],
                'Z': [1, 2, 3, 1, 2, 3, 1, 2, 3]
            })
In [4]: %%R -i df
        ggplot(data = df) + geom_point(aes(x = X, y= Y, color = Letter, size = Z))

以上代码结果输出如下:
Jupyter notebook安装R内核和简单实例_第1张图片

参考:
Jupyter安装r内核

你可能感兴趣的:(工具类)