【问题标题】:Map of India with Longitude-Latitude Grid Cells Filled in R经纬度网格单元格填充为 R 的印度地图
【发布时间】:2015-08-19 13:02:23
【问题描述】:

我有印度 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 on Map 但不幸的是,这些方法在我的情况下不起作用。任何将不胜感激。

【问题讨论】:

  • 你为什么使用geom_tile?
  • 尊敬的律师,没有geom_tile(),我将只获得印度的一半边界。没有这个,我无法获得数据的填充图。
  • 尊敬的律师,我们将不胜感激。我仍然被困在这里。
  • 您能否提供至少一些数据,也许使用 dput()?或者让那些花时间回答的人重复你的问题。我很感兴趣,但如果不能用一些数据运行你的代码,我就不能提供太多。
  • 尊敬的律师,here您可以找到数据集。

标签: r plot ggplot2 maps sp


【解决方案1】:

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

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())

【讨论】:

  • 尊敬的律师,感谢您的回复。我在这个问题中的数据是网格数据。这里不包含任何状态。根据您之前的建议,我在上面提供了一个链接作为示例数据集。
猜你喜欢
  • 1970-01-01
  • 2022-10-18
  • 1970-01-01
  • 1970-01-01
  • 2016-05-21
  • 1970-01-01
  • 2015-09-13
  • 2021-09-26
  • 2015-08-03
相关资源
最近更新 更多