integer(0) 绘制 shapefile 和点时
integer(0) when plotting a shapefile and points
我在 shapefile 上绘制点,R 在完成命令后继续打印 "integer(0)"。它绘制得很好,可以在这个可重现的示例中看到(颜色不和谐,因为 FUN=had ;-))
### get Germany as shp
Germany.shp<-getData("GADM", country="DEU",level=1,download=T,path=getwd())
par(mfrow=c(1,2))
plot(Germany.shp, col="magenta", main="plots normally")
### make up some spatial points (yes, the proper cities in Germany)
points.df<-data.frame(name=c("Berlin","Frankfurt","Rostock"),
lat=c(52.5243700,50.1155200,54.0887000), long=c(13.4105300,8.6841700,12.1404900))
coordinates(points.df)=~long+lat ### converts df to spatial df
crs(points.df)<-CRS("+init=epsg:4326") ### defines CRS
points.df<-spTransform(points.df,crs(Germany.shp)) ### project to same CRS as Germany.shp
### plot
plot(Germany.shp, col="magenta", sub="is 0 actually in integer? just asking",main="integer 0",)+
points(points.df,col="blue", pch=16,cex=2.2)
### !!! ### CONSOLE shows integer(0), plots perfectly well though ### !!! ###
一开始我真的很担心,因为我在我的实际数据集中绘制了 35000 个点。所以我做了这个例子来交叉检查,城市在正确的地方。但是我使用的是 markdown 并且有 10-15 个这样的图,因此必须手动删除 "integer(0)" 控制台输出。 烦人 ;)
似乎有几种解决方案。
最简单的方法是将 plot() 添加到一个对象中:
x<-plot()
其他人建议将其包装在 invisible()
中或将降价设置调整为 results="hide"
但是将绘图变成对象 (imo) 可以提供最大的灵活性和稍后安排对象的机会,以便您可以重新绘制它们!
我在 shapefile 上绘制点,R 在完成命令后继续打印 "integer(0)"。它绘制得很好,可以在这个可重现的示例中看到(颜色不和谐,因为 FUN=had ;-))
### get Germany as shp
Germany.shp<-getData("GADM", country="DEU",level=1,download=T,path=getwd())
par(mfrow=c(1,2))
plot(Germany.shp, col="magenta", main="plots normally")
### make up some spatial points (yes, the proper cities in Germany)
points.df<-data.frame(name=c("Berlin","Frankfurt","Rostock"),
lat=c(52.5243700,50.1155200,54.0887000), long=c(13.4105300,8.6841700,12.1404900))
coordinates(points.df)=~long+lat ### converts df to spatial df
crs(points.df)<-CRS("+init=epsg:4326") ### defines CRS
points.df<-spTransform(points.df,crs(Germany.shp)) ### project to same CRS as Germany.shp
### plot
plot(Germany.shp, col="magenta", sub="is 0 actually in integer? just asking",main="integer 0",)+
points(points.df,col="blue", pch=16,cex=2.2)
### !!! ### CONSOLE shows integer(0), plots perfectly well though ### !!! ###
一开始我真的很担心,因为我在我的实际数据集中绘制了 35000 个点。所以我做了这个例子来交叉检查,城市在正确的地方。但是我使用的是 markdown 并且有 10-15 个这样的图,因此必须手动删除 "integer(0)" 控制台输出。 烦人 ;)
似乎有几种解决方案。
最简单的方法是将 plot() 添加到一个对象中:
x<-plot()
其他人建议将其包装在 invisible()
中或将降价设置调整为 results="hide"
但是将绘图变成对象 (imo) 可以提供最大的灵活性和稍后安排对象的机会,以便您可以重新绘制它们!