geom_tile不显示地图

时间:2014-07-06 20:16:13

标签: r plot ggplot2 maps

我有this个数据。我正在尝试使用以下代码绘制构面图。 不幸的是,它没有显示瓷砖图,我没有给出地图。给予的是这里。它只显示了传说。 怎么了?怎么解决这个问题? 谢谢, 一个 使用的代码是

geomerror<-read.csv("Test_Geom_Tile.csv")
str(geomerror)
plot<- ggplot(geomerror,aes(x=Longitude,y=Latitude))+
  geom_tile(aes(fill=Value),alpha=0.6)+
  facet_wrap(~Par)+
  scale_fill_gradientn(name="Test",     colours=rev(brewer.pal(11,rev("RdYlBu"))),breaks=seq(-10,15,by=5))+
  coord_fixed()
plot

What i got is here, this do not show map

1 个答案:

答案 0 :(得分:0)

问题似乎是您的不同Par值的数据位于不同的网格上。 geom_tile层期望所有观察具有相同的x / y值集。您的数据不是这种情况。您的AA和CC值匹配,因此您可以绘制

ggplot(subset(geomerror,Par%in%c("AA", "CC")),aes(x=Longitude,y=Latitude))+
  geom_tile(aes(fill=Value),alpha=0.6)+
  facet_wrap(~Par)+
  scale_fill_gradientn(name="Test", colours=rev(brewer.pal(11,rev("RdYlBu"))),breaks=seq(-10,15,by=5))+
  coord_fixed()

同样适用于BB和DD

ggplot(subset(geomerror,Par%in%c("BB", "DD")),aes(x=Longitude,y=Latitude))+
  geom_tile(aes(fill=Value),alpha=0.6)+
  facet_wrap(~Par)+
  scale_fill_gradientn(name="Test", colours=rev(brewer.pal(11,rev("RdYlBu"))),breaks=seq(-10,15,by=5))+
  coord_fixed()

但除非您可以将它们对齐到同一网格,否则无法使用构面绘制它们。您可以考虑使用grid.arrage包中的gridExtra来布局相同配置中的4个单独的图。

相关问题