美国州概述没有出现在ggplot2中

时间:2016-10-10 22:07:52

标签: r ggplot2

我认为我正在努力解决一个相当简单的问题,但是我没有自己解决这个问题或找到一个可能有解决方案的帖子。我正在绘制美国,然后在地图上添加点数。但是,当我绘制地图时,不显示统计数据的轮廓。有什么建议?也许我想知道的路径,我没有使用合适的地图?代码如下。提前感谢您的帮助和建议。

study2 <- c("ABQ", "ATL", "BUF", "CHS", "DEN", "MEM", "ORF", "Apker", "Apker", "Drewry", "Gardner", "Gould", "Gould", "Gould", "Hooker", "Sun", "Tredick", "Tredick", "Tredick", "Wilton") #city and study labels
lat2 <- c(35.5, 33.44, 42.52, 32.53, 39.44, 35.9, 36.50, 37.18, 39.7, 33.23, 44.1, 36.1, 35.6, 33.4, 32.3, 41.8, 36.31, 36, 36, 36.3)

long2 <- c(-106.36, -84.23, -78.52, -80.10, -104.59, -90.2, -76.17, -104.55, -107.51, -79.12, -75.45, -105.19, -106.23, -105.42, -83.3, -77.48, -76.27, -76.29, -76, -92.51)

elev.df2 <- data.frame(study2, lat2, long2)

shape2 <- c(15, 1, 19, 17, 2, 0, 18, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8)

states <- map_data("state")


uv.map <- ggplot() + 

          coord_fixed() +

  geom_polygon(data = states, 
               aes(x = long, y = lat, group = group), fill = "gray90") +

  geom_point(data = elev.df2, 
             aes(x = long2, y = lat2), 
             shape = shape2, 
             col = "black", 
             size = c(4,4,4,4,4,4,4,2,2,2,2,2,2,2,2,2,2,2,2,2)) +

  labs(x = "Longitude", y = "Latitude", title = "") +

  theme_bw() +

  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        axis.line = element_line(colour = "black")) +

  coord_equal(ratio=1)

enter image description here

1 个答案:

答案 0 :(得分:4)

使用color=的{​​{1}}参数绘制状态边界。只需将其设置为您想要的任何颜色

geom_polygon

enter image description here