【发布时间】:2019-06-06 22:16:09
【问题描述】:
我想使用 ggplot、maps 和 mapdata 在世界地图上可视化一些数据
.xls 文件的链接是here*
让我们看看代码:
library(maps)
library(mapdata)
library(readxl)
library(ggplot2)
library(ggthemes)
library(mapproj)
mapka <- read_xls(path="Yourpath/mapy2.xls")
m <-map_data("world")
choro <-merge(m, mapka, by="region", all.x=TRUE)
for (i in 1:nrow(choro)) {
if (is.na(choro$a[i]==TRUE)){choro$a[i]<-0}
if (is.na(choro$b[i]==TRUE)){choro$b[i]<-0}}
ggplot()+
geom_map(data=choro, map=choro, aes(long,lat, map_id=region, fill=a)) +
theme_bw() +
xlab("") +
ylab("") +
scale_x_continuous(labels=NULL) +
scale_y_continuous(labels=NULL)
怎么了?以前我没有这样的问题。看起来很可怕。
*有人知道更好的免费 .xls/.xlsx 存储库吗?
【问题讨论】: