在绘制多个国家/地区时绘制填充问题

时间:2017-04-18 15:29:30

标签: r plot ggplot2 mapping

我正在尝试用秘鲁和厄瓜多尔绘制地图,这里有两个简单的纬度和长点(秘鲁的圣何塞和利马)。

在将秘鲁和厄瓜多尔纳入我的地图时,我遇到了填充问题。

library(ggplot2)
library(ggmap)
library(maps)
library(mapdata)

peru_ecuador <- map_data("world",c("peru", "ecuador"))

# Add study site points (San Jose and Lima)
points <- data.frame(
long = c(-79.81, -77.04),
lat = c(-6.77, -12.04),
names = c("San Jose", "Lima"),
stringsAsFactors = FALSE
)


# Plot the map
ggplot() + 
geom_polygon(data = peru_ecuador, aes(x=long, y = lat), fill = "grey40", color 
= "grey90", alpha = 1) +
geom_point(data = points, aes(x = long, y = lat), color = "red", size = 2, 
alpha = 0.8) +
geom_text(aes(x = long, y = lat, label = c("San Jose", "Lima")), data = 
points, size = 2, hjust = 1.3) +
geom_area(x = 10) +
coord_fixed(1.3) +
labs(x = "Longitude", y = "Latitude", size = 2) +
theme_bw(base_size = 5)

我也非常喜欢一些关于如何最好地调整地图的绘图区域窗口的建议。如改变x和y轴的宽度和长度。当我只绘制一张秘鲁地图时,我的一些地图信息会被绘图区域的大小所截断。请参阅以下内容:

peru <- map_data("world","peru")
ggplot() + 
geom_polygon(data = peru, aes(x=long, y = lat), fill = "grey40", color = 
  "grey90", alpha = 1) +
  geom_point(data = points, aes(x = long, y = lat), color = "red", size = 2, 
  alpha = 0.8) +
  geom_text(aes(x = long, y = lat, label = c("San Jose", "Lima")), data = 
  points, size = 2, hjust = 1.3) +
  geom_area(x = 10) +
  coord_fixed(1.3) +
  labs(x = "Longitude", y = "Latitude", size = 2) +
  theme_bw(base_size = 5)

0 个答案:

没有答案