Art*_*Art 5 gis plot r ggplot2
我一直在玩双变量 choropleth 地图,并且一直在研究如何创建类似于Joshua Stevens在这里显示的那个的 2d 图例:
为了说明这一挑战,我们不需要使用地图。下面的代码就足够了:
#test desired legend appearance
library(ggplot2)
library(reshape2)
#use color scheme shown here http://www.joshuastevens.net/cartography/make-a-bivariate-choropleth-map/
bvColors=c("#be64ac","#8c62aa","#3b4994","#dfb0d6","#a5add3","#5698b9","#e8e8e8","#ace4e4","#5ac8c8")
legendGoal=melt(matrix(1:9,nrow=3))
test<-ggplot(legendGoal, aes(Var1,Var2))+ geom_tile(aes(fill = as.factor(value)))
test<- test + scale_fill_manual(name="Var1 vs Var2",values=bvColors,drop=FALSE)
test
Run Code Online (Sandbox Code Playgroud)
它创建了一个看起来像我想要的图例的图,但当然图例是所有级别的垂直条。我希望图例看起来像情节本身。有没有办法做到这一点?谢谢!
不是一个完整的答案,但我认为你需要使用指南。
ggplot(legendGoal,
aes(Var1,Var2,
col=as.factor(value),
fill=as.factor(value))) +
geom_tile() +
guides(col = guide_legend(nrow = 3))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1521 次 |
最近记录: |