将相同的自定义颜色分配给来自不同数据框但在同一图中的两条线

时间:2015-06-05 10:19:47

标签: r plot ggplot2

我有以下图表,绘制来自两个不同数据框的数据:

ggplot() + 
  stat_summary( data = d0_400, aes(x=number, y=(1-value), shape=as.factor(0), size=1 ) , fun.y=mean, geom="line" ) +
  stat_summary( data = d0_400, aes(x=number, y=(1-value), shape=as.factor(0), size=4 ) , fun.y=mean, geom="point" ) +
  stat_summary( data = d1_400, aes(x=number, y=(1-value), shape=as.factor(1), size=1 ) , fun.y=mean, geom="line" ) +
  stat_summary( data = d1_400, aes(x=number, y=(1-value), shape=as.factor(1), size=4 ) , fun.y=mean, geom="point" ) +
  scale_size(range = c(1,5), guide=FALSE) + 
  scale_shape_manual(values=c(0,1) )

使用此代码,我得到以下图:

enter image description here

我想取而代之的是:

  • 线条和形状的自定义十六进制颜色
  • 可选:形状图例中的形状看起来更大,因为它们难以在此尺寸中区分,并用白色填充它们。

1 个答案:

答案 0 :(得分:1)

对于彩色线条,只需添加colour参数

p = ggplot() + 
  stat_summary( data = d0_400, ..., geom="line", colour = "#hexnum" )

此外,快速谷歌的可选问题带我去了here

提供的解决方案是

p = p + guides(shape=guide_legend(override.aes=list(size=5)))
相关问题