【发布时间】:2021-10-19 07:33:47
【问题描述】:
我的代码:
library("ggplot2")
library("sf")
library("rnaturalearth")
library("rnaturalearthdata")
library("ggspatial")
chesapeake_bay <- ne_countries(scale = "medium", returnclass = "sf")
plot<-ggplot(data = chesapeake_bay) +geom_sf(fill="darkgreen") + coord_sf(xlim = c(-77.5, -75), ylim = c(37, 40),expand = TRUE)+
xlab("Longitude") + ylab("Latitude") + ggtitle("Chesapeake Bay")+
theme(panel.background = element_rect(fill = "lightblue")) +
annotate(geom = "text",x = -76.1,y = 37.8,label = "Chesapeake Bay",color = "brown",size = 3, angle=90) +
annotation_north_arrow(location = "tl",pad_x = unit(0.5, "cm"),pad_y = unit(1, "cm"),height=unit(1,"cm"),width=unit(0.5,"cm")) +
theme(panel.grid.major = element_line(linetype = "dashed", size = 0.2))
此代码应该生成切萨皮克湾地图的绘图,但是当我运行它时,它不会生成任何东西。
【问题讨论】:
-
如果你不打电话给
plot,这肯定不会产生情节。你的代码对我来说很好用 -
我调用 plot 得到这个:function (x, y, ...) UseMethod("plot")
-
这是
plot函数,通常我们不给存储对象函数名称,我建议你更改存储对象图的名称