使用knitr包含ggmap
我正在尝试使用knitr中的ggmap库包括地图:使用knitr包含ggmap,r,knitr,ggmap,R,Knitr,Ggmap,我正在尝试使用knitr中的ggmap库包括地图: library(ggmap) murder = subset(crime, offense='murder') qmplot(lon, lat, data=murder) 它在knitr之外运行良好,但当我尝试在knitr中运行此代码块时,会出现以下错误: UseMethod(“depth”)中出错:没有适用于类为“NULL”的对象的“depth”方法 最终PDF中没有地图 我尝试将qmplot行包装在evaluate(…)中,但没有成功
library(ggmap)
murder = subset(crime, offense='murder')
qmplot(lon, lat, data=murder)
它在knitr之外运行良好,但当我尝试在knitr中运行此代码块时,会出现以下错误:
UseMethod(“depth”)中出错:没有适用于类为“NULL”的对象的“depth”方法
最终PDF中没有地图
我尝试将qmplot行包装在evaluate(…)中,但没有成功
图书馆输出(knitr);sessionInfo()
我还尝试通过Rscript(即,不是从VIM内部)运行相同的代码,如下所示:
Rscript -e "library(knitr); knit('map.Rnw')"
我得到了一个类似的错误:
Error in UseMethod("depth") :
no applicable method for 'depth' applied to an object of class "NULL"
Calls: knit ... grid.draw -> grid.draw.gTableChild -> upViewport -> depth
使用GGMAPv2.3和ggplot v0.9.3.1,我发现了问题:我在使用tikz设备将地图包含在最终文档中。tikz设备似乎不适用于地图(或至少更大的地图) 当我将设备更改为pdf或png时,地图包含在我的文档中,没有任何问题。在调用长
ggplot
命令时遇到此错误(R3.4.1),在大数据帧(28x3200)上附加了许多附加命令
分离命令解决了这一问题,并且可以说提高了可读性:
z2 <- ggplot(z, aes(x=T,y=A,fill=F), title="D")
z2 <- z2 + geom_bar(aes(fill=F), stat ="identity", position="dodge", colour="black")
z2 <- z2 + facet_grid(P~T,scales='free_x',space='free_x')
z2 <- z2 + theme(strip.text.y = element_text(angle = 0), axis.text.x = element_text(angle = 270))
z2 <- z2 + guides(col=guide_legend(ncol=1))
z2
z2我无法重现这个问题。请张贴库(knitr);sessionInfo()
。和ggmap
是v2.3
?这很奇怪;我的环境与你几乎完全相同,但我仍然无法重现问题tikz不工作的原因是什么?我真的很想这样。
ggplot(z, aes(x=T,y=A,fill=F), title="D") + geom_bar(aes(fill=F), stat ="identity", position="dodge", colour="black") + facet_grid(P~T,scales='free_x',space='free_x')
+ theme(strip.text.y = element_text(angle = 0), axis.text.x = element_text(angle = 270)) + guides(col=guide_legend(ncol=1))
z2 <- ggplot(z, aes(x=T,y=A,fill=F), title="D")
z2 <- z2 + geom_bar(aes(fill=F), stat ="identity", position="dodge", colour="black")
z2 <- z2 + facet_grid(P~T,scales='free_x',space='free_x')
z2 <- z2 + theme(strip.text.y = element_text(angle = 0), axis.text.x = element_text(angle = 270))
z2 <- z2 + guides(col=guide_legend(ncol=1))
z2