颜色渐变与ggplot

编程入门 行业动态 更新时间:2024-10-09 18:23:27
本文介绍了颜色渐变与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

本文发布于:2023-11-30 22:36:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651676.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:颜色   ggplot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!