本文介绍了颜色渐变与ggplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些地理x,y,z数据,我绘制如下
I have some geographic x,y,z data which I plot as follows
p<-ggplot(aes(x=x,y=y,fill=z),data=my_data)
I then apply a gradient
p<-p + scale_fill_gradient(low = "pink", high = "green")然后平铺并显示数据
p<-p + geom_tile() p:
>
我们可以用任何其他选项替换 scale_fill_gradient()调用,例如
One would think then, that I could replace the scale_fill_gradient() call with any number of other options such as
p<-p + scale_color_hue() p<-p + scale_colour_gradientn(colours=c("#E5F5F9","#99D8C9","#2CA25F")) p<-p + scale_colour_gradientn(colours = rainbow(7)) p<-p + scale_colour_brewer()可以工作。
但他们没有,我得到的是一个蓝色渐变
But they don't, all I get is a gradient of blue.
任何想法,为什么会是这样,以及我如何能产生许多快乐的颜色?
Any thoughts as to why this might be, and how I can generate lots of happy colours?
推荐答案这些缩放函数有两个版本,一个用于 color ,一个用于 fill 。您只需要使用填充版本,即 scale_fill_hue 等。
There are two versions of these scale functions, one for colour and one for fill. You just needed to use the fill versions, i.e. scale_fill_hue, etc.
更多推荐
颜色渐变与ggplot
发布评论