我曾尝试在Colab中运行演示文稿“用PYTHON和R可视化演示的多语言数据分析”
但它说,懒散的人是不存在的
当我尝试将其安装为foloows时
%%R
install.packages("lazyeval")
它的输出像
R[write to console]: Installing package into ‘/usr/local/lib/R/site-library’ (as ‘lib’ is unspecified)
R[write to console]: trying URL 'https://cran.rstudio.com/src/contrib/lazyeval_0.2.2.tar.gz'
R[write to console]: Content type 'application/x-gzip' R[write to console]: length 83482 bytes (81 KB)
R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]: = R[write to console]:
R[write to console]: downloaded 81 KB
R[write to console]:
R[write to console]: R[write to console]: The downloaded source packages are in ‘/tmp/Rtmp6hM38b/downloaded_packages’ R[write to console]: R[write to console]:
但不显示任何绘图,输出单元格内的完整html页面如下(复制粘贴的单元格内容)
<html>
<body>
<!--StartFragment--><span style="color: rgb(33, 33, 33); font-family: Roboto, Noto, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">GGPlot with 9 elements.</span><span style="color: rgb(33, 33, 33); font-family: Roboto, Noto, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"></span>
data | R/rpy2 DataFrame (6161 x 8)Request.IDStatusAction.Type...AddressPlatformSubmitted.By'REQ194189''Closed''Repair P......'Concord ...'''bsmyth''REQ194190''Closed''Repair P...'Sunset R...'''bsmyth''REQ194191''Closed''Repair P...'Blanchar...'''bsmyth''REQ194192''Closed''Repair P...'Rindge A...'''bsmyth'..................'REQ545410''Assigned''Repair P...'''iOS''web-serv...'REQ545521''Assigned''Repair P...'''''web-serv...'REQ545560''Assigned''Repair P...'''Android''web-serv...'REQ545621''Assigned''Repair P...'''''web-serv... | Request.ID | Status | Action.Type | ... | Address | Platform | Submitted.By | 'REQ194189' | 'Closed' | 'Repair P... | ... | 'Concord ... | '' | 'bsmyth' | 'REQ194190' | 'Closed' | 'Repair P... | | 'Sunset R... | '' | 'bsmyth' | 'REQ194191' | 'Closed' | 'Repair P... | | 'Blanchar... | '' | 'bsmyth' | 'REQ194192' | 'Closed' | 'Repair P... | | 'Rindge A... | '' | 'bsmyth' | ... | ... | ... | | ... | ... | ... | 'REQ545410' | 'Assigned' | 'Repair P... | | '' | 'iOS' | 'web-serv... | 'REQ545521' | 'Assigned' | 'Repair P... | | '' | '' | 'web-serv... | 'REQ545560' | 'Assigned' | 'Repair P... | | '' | 'Android' | 'web-serv... | 'REQ545621' | 'Assigned' | 'Repair P... | | '' | '' | 'web-serv...
-- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | --
'REQ194189' | 'Closed' | 'Repair P... | ... | 'Concord ... | '' | 'bsmyth'
'REQ194190' | 'Closed' | 'Repair P... | | 'Sunset R... | '' | 'bsmyth'
'REQ194191' | 'Closed' | 'Repair P... | | 'Blanchar... | '' | 'bsmyth'
'REQ194192' | 'Closed' | 'Repair P... | | 'Rindge A... | '' | 'bsmyth'
... | ... | ... | | ... | ... | ...
'REQ545410' | 'Assigned' | 'Repair P... | | '' | 'iOS' | 'web-serv...
'REQ545521' | 'Assigned' | 'Repair P... | | '' | '' | 'web-serv...
'REQ545560' | 'Assigned' | 'Repair P... | | '' | 'Android' | 'web-serv...
'REQ545621' | 'Assigned' | 'Repair P... | | '' | '' | 'web-serv...
ListVector with 1 elements.[no name][RTYPES.ENVSXP] | [RTYPES.ENVSXP]
[RTYPES.ENVSXP]
add: function clone: function find: function get_scales: function has_scale: function input: function n: function non_position_scales: function scales: list super:
...
compute_layout: function draw_back: function draw_front: function draw_labels: function draw_panels: function finish_data: function init_scales: function map_data: function params: list setup_data: function setup_params: function shrink: TRUE train_scales: function vars: function super:
ListVector with 3 elements.x[RTYPES.STRSXP]y[RTYPES.STRSXP]weight[RTYPES.STRSXP] | [RTYPES.STRSXP] | [RTYPES.STRSXP] | [RTYPES.STRSXP]
[RTYPES.STRSXP]
[RTYPES.STRSXP]
[RTYPES.STRSXP]
<!--EndFragment-->
</body>
</html>
不幸的是,Presentation项目似乎无法添加问题
在SO Using R in Python with Rpy2: how to ggplot2?有一个帖子,上面有代码
import numpy as np
import pandas as pd
import rpy2.robjects.packages as packages
import rpy2.robjects.lib.ggplot2 as ggplot2
import rpy2.robjects as ro
R = ro.r
datasets = packages.importr('datasets')
mtcars = packages.data(datasets).fetch('mtcars')['mtcars']
gp = ggplot2.ggplot(mtcars)
pp = (gp
+ ggplot2.aes_string(x='wt', y='mpg')
+ ggplot2.geom_point(ggplot2.aes_string(colour='qsec'))
+ ggplot2.scale_colour_gradient(low="yellow", high="red")
+ ggplot2.geom_smooth(method='auto')
+ ggplot2.labs(title="mtcars", x='wt', y='mpg'))
pp.plot()
R("dev.copy(png,'/tmp/out.png')")
但在Colab中,它只是输出
R[write to console]:
geom_smooth()
using method = 'loess' and formula 'y ~ x'
IntVector with 1 elements. 5
在Colab的Python笔记本中使用R ggplot2代码的正确方法是什么?如何修复笔记本
那是6年前的演讲。它应该使用当时使用的Python和R版本(以及它们各自的包,也包括当时的版本)运行
否则,一些内容会被添加到rpy2文档或其他最近的文章中
相关问题 更多 >
编程相关推荐