首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在R中绘制地图,但未显示任何内容

在R中绘制地图,但未显示任何内容
EN

Stack Overflow用户
提问于 2021-10-19 07:33:48
回答 1查看 47关注 0票数 0

我的代码:

代码语言:javascript
复制
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))

这段代码应该生成一张切萨皮克湾的地图,但是当我运行它时,它没有生成任何东西。

EN

回答 1

Stack Overflow用户

发布于 2021-10-19 07:42:29

我认为这是命名空间的问题,因为plot是一个基本的R函数。将对象重命名为plot.01或类似的名称可能会解决此问题。

代码语言:javascript
复制
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.01
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69626720

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档