在R中绘制时如何使颜色平滑变化 [英] how to make colors change smoothly when plotting in R

查看:46
本文介绍了在R中绘制时如何使颜色平滑变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ENV

R 3.3.1

小型数据

rdn<-c(0.8,1.8,2.8)
tdn<-c(1,2,3,4,5,6,7,8,9)

idn<-matrix(c(0.3, 0.3, 0.3, 0.2, 0.2, 0.4, 0.1, 0.1, 0.5, 0, 0.2, 0.5, 0, 0.3, 0.6, 0, 0.4, 0.6, 0, 0.4, 0.6, 0, 0.5, 0.7, 0, 0.5, 0.7), nrow=9, ncol=3, byrow=T)

我现在拥有的东西:

代码

filled.contour(tdn, rdn, idn,
    color.palette=colorRampPalette(c("blue","yellow","red")), 
    plot.title=title(main="Detail", sub="detail", 
                    xlab="t", ylab="lambda"), 
    plot.axes = { axis(side = 1, at = tdn, labels = tdn)
                  axis(side = 2, at = rdn, labels = rdn) },
    key.title=title(main="ratio"),
    key.axes = axis(4, seq(0, 1, by = 0.1)))

当前结果

问题

颜色范围不是我想要的.颜色之间存在边界,因此颜色不会从深蓝色变为深红色.

The color range is not what I want. There are borders among colors so colors do not change smoothly from deep blue to deep red.

期望

问题

在绘制R时,如何使颜色像我的 Expeded 一样平滑地变化?我该如何解决以上问题?而且 rainbow 也不适合我.谢谢.

how to make colors change smoothly like my Expeced figure when plotting in R? How do I remove problems above? And rainbow not works for me either. Thanks.

编辑

遵循Haboryme的解决方案

Follow Haboryme's solution

前景不会消失.

推荐答案

接近@setempler答案,但您可能会发现它与预期的输出更接近:

Close to @setempler answer but you might find it a bit closer to your expected output:

par(fg = NA,col="black")
filled.contour(x=tdn,
               y=rdn,
               z=idn,
               color.palette=colorRampPalette(c("blue","yellow","red")), 
               plot.title=title(main="Detail", sub="detail", 
                                xlab="t", ylab="lambda"), 
               nlevels=200,
               plot.axes = { axis(side = 1, at = tdn, labels = tdn)
                 axis(side = 2, at = rdn, labels = rdn) },
               key.title=title(main="ratio"),
               key.axes = axis(4, seq(0, 1, by = 0.1)))

这篇关于在R中绘制时如何使颜色平滑变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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