0

我有印度 357 个网格的数据。每个网格都有一些价值。我想在 R 中绘制它。我使用以下几行

library(maps)
library(ggplot2)
data <- read.csv("foo.csv")
ind <- map(database = "world", regions = "india", exact = FALSE, boundary = T)
india <- map_data(ind , region = "india", exact = F)
(ggplot(aes(x=x, y=y, fill=z), data=data) + geom_tile()) + geom_polygon(data=india, aes(x=long, y=lat, group=group), colour="black", fill="red", alpha=0)

但是我得到了一张非常糟糕的地图。 我怎样才能改善这个形象?我 在地图上的 R Plot Filled Longitude-Latitude Grid Cells中看到了一些好方法, 但不幸的是,这些方法在我的情况下不起作用。任何将不胜感激。

4

1 回答 1

0

您需要有一个与您的观察相关的印度州。有了这个,我相信你可以合并你的地图数据和印度州的观察数据。这是示例代码。

states_map <- map_data("state")
fee_map <- merge(states_map, spendstate, by.x = "region", by.y = "state")
fee_map <- arrange(fee_map, group, order) # eeed to sort polygons in right order

然后,使用我的代码,例如:

ggplot(fee_map, aes(x = long, y = lat,  group = group, fill = obs)) + 
  geom_polygon() + 
  coord_map("polyconic") + reestheme + labs(x = "", y = "") +
  scale_fill_gradient(low = "green", high = "red") +
  theme(legend.position = "bottom") + 
  theme( legend.position=c(0,0),  legend.justification=c(0, 0)) + # lower left and lower left just
  theme(legend.text = element_text(colour= "black", size=10, hjust=0,vjust=0,face="plain")) + 
  theme(axis.text = element_blank()) + theme(axis.ticks = element_blank())
于 2015-06-17T11:21:59.260 回答