我的代码:
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))这段代码应该生成一张切萨皮克湾的地图,但是当我运行它时,它没有生成任何东西。
发布于 2021-10-19 07:42:29
我认为这是命名空间的问题,因为plot是一个基本的R函数。将对象重命名为plot.01或类似的名称可能会解决此问题。
chesapeake_bay <- ne_countries(scale = "medium", returnclass = "sf")
plot.01<-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.01https://stackoverflow.com/questions/69626720
复制相似问题