用ggplot2中的不同颜色调色板进行重叠显示 [英] Overplotting with different colour palettes in ggplot2

查看:357
本文介绍了用ggplot2中的不同颜色调色板进行重叠显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的堆栈溢出阅读器,

我有一个数据集,为此我有原始数据,并为此另外计算某种平滑函数。然后我想将原始数据绘制为点,并将平滑线绘制为线。这适用于以下内容:

  Loc < -  seq(from = 1,to = 50)
Loc< ; - 附加(Loc,Loc)
x <-seq(从= 0到= 45,by = 0.01)
Val < - 样本(x,100)
标签< - NULL
labels [1:50]< - 'one'
labels [51:100]< - 'two'

x2 < - seq(from =
Val2 < - sample(x2,100)
raw < - data.frame(loc = Loc,value = Val,lab = labels)
smooth < - data.frame(loc = Loc,value = Val2,lab = labels)

pl < - ggplot(raw,aes(loc,value,color = lab))+ geom_point()+ geom_line(data = smooth)
print(pl)

像这样:



scale_colour_hue(l = 40),但是这会导致geom_points()也变得更暗。



感谢您的任何建议!

解决方案

我没有一个完美的答案给你,但我确实有一个工程。你可以单独控制你的线条的颜色,把它们分割成不同的几何形状,如下所示:

  ggplot(raw,aes(loc,值))+ 
geom_point(aes(col = lab))+
geom_line(data = smooth [smooth $ lab ==one,],color =blue,size = 1)+
geom_line(data = smooth [smooth $ lab ==two,],color =black,size = 1)



这样做的缺点是您必须手动指定行选择,但好处是您可以手动指定每行的视觉属性。



其他选择是使用相同的调色板,但使行更大和部分透明,如下所示:

  ggplot(raw,aes (数据=平滑,大小= 2,alpha = 0.5)
geom_point()+
pre>



呦你应该能够从这里定制适合你需要的东西。


Dear stack overflow readers,

I am having a dataset for which I have "raw" data and for which I additionally compute some kind of smoothing function for. I then want to plot the raw data as points, and the smoothing as a line. This works with the following:

Loc <- seq(from=1,to=50)
Loc <- append(Loc,Loc)
x <- seq(from=0,to=45,by=0.01)
Val <- sample(x,100)
labels <- NULL
labels[1:50] <- 'one'
labels[51:100] <- 'two'

x2 <- seq(from=12,to=32,by=0.01)
Val2 <- sample(x2,100)
raw <- data.frame(loc=Loc,value=Val,lab=labels)
smooth <- data.frame(loc=Loc,value=Val2,lab=labels)

pl <- ggplot(raw,aes(loc,value,colour=lab)) + geom_point() + geom_line(data=smooth)
print(pl)

The result looks like this:

The problem is that my actual data contains so many data points that using the same colour palette is going to be very confusing (the difference between point and line will be almost indistinguishable). Preferably, I would make the geom_lines() slightly darker. I've tried with scale_colour_hue(l=40), but that results in the the geom_points() to be darker as well.

Thanks for any suggestions!

解决方案

I don't have a perfect answer for you, but I do have one that works. You can individually control colors of your lines by splitting them into separate geometries, like so:

ggplot(raw,aes(loc,value)) + 
geom_point(aes(col=lab)) + 
geom_line(data=smooth[smooth$lab=="one",], colour="blue", size=1) + 
geom_line(data=smooth[smooth$lab=="two",], colour="black", size=1)

The disadvantage of this is that you have to manually specify the row selection, but the advantage is that you can manually specify the visual properties of each line.

The other option is to use the same palette but to make the lines bigger and partially transparent, like so:

ggplot(raw,aes(loc,value,colour=lab)) + 
geom_point() + 
geom_line(data=smooth, size=2, alpha=0.5)

You should be able to customize things from here to suit your needs.

这篇关于用ggplot2中的不同颜色调色板进行重叠显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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