【发布时间】:2017-02-16 03:58:03
【问题描述】:
所以我修改了形状配置文件以添加夏威夷和阿拉斯加,因此我的数据框使用的长纬度坐标与下面显示的 maps 包 (map_data("state")) 提供的库存州坐标不同
states <- data.frame(state.center, state.abb)
states
x y state.abb
1 -86.7509 32.5901 AL
2 -127.2500 49.2500 AK
3 -111.6250 34.2192 AZ
4 -92.2992 34.7336 AR
5 -119.7730 36.5341 CA
我的数据框的坐标如下。
当我使用下面的代码绘制它时,我得到一张没有任何州缩写标签的地图。
p <- function(data, brks, title) {
ggp <- ggplot() +
geom_polygon(data = data, aes(x = long, y = lat, group = group,
fill = IMSUB), color = "black", size = 0.15) +
scale_fill_gradient2(limits=c(-1,1), breaks = c(-1, 0, 1), labels=c("Trump", 0, "Clinton"), low = "red", mid = "white",
high = "blue", midpoint = 0, space = "Lab",
na.value = "grey50", guide = "colourbar") +
theme_nothing(legend = TRUE) + labs(title = title, fill = "") +
geom_text(data = states, aes(x = x, y = y, label = state.abb), size = 3)
return(ggp)
}
我觉得我可以用us50 中的坐标替换states 数据框中的坐标,但我不确定如何正确替换它们。
【问题讨论】: