geom_line中的平滑颜色 [英] Smooth colors in geom_line

查看:1671
本文介绍了geom_line中的平滑颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ggplot2 ,我希望在一个只有几个数据点的图中平滑的颜色线。因为,我尝试的比例(例如 scale_color_gradient2 )似乎不内插颜色,而是单色色段。

Using ggplot2, I would like color lines "smoothly" in a plot where I have only few datapoints. As is, the scales I tried (e.g. scale_color_gradient2) do not seem to interpolate colors, but instead color segments monochromatically.

代码示例:

ggplot(data.frame(x=1:5)) + geom_line(aes(x=x, y=x, color=x), size=3) + 
   scale_color_gradient2()

推荐答案

您可以增加1到5之间的点数:

You could increase the amount of points between 1 and 5:

df <- data.frame(x=seq(1,5,0.001))

ggplot(df) + geom_line(aes(x=x, y=x, color=x), size=3) + 
   scale_color_gradient2()

这篇关于geom_line中的平滑颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆