图例颜色混合在scale_color_manual ggplot2中

时间:2018-01-10 15:42:58

标签: r ggplot2

我有5个数据帧(实际上有一个和4个子集相同的一些滤镜),我们的想法是根据颜色绘制它们并在图例上有相应的颜色。但是在图例中颜色是混合的,名称的顺序是保持不变的。我不确定他们是如何订购的,但不是根据我的意见。

我的代码是:

 ggplot(regression_with_pred, aes(x= countF, y= countM)) + 
  geom_point(alpha = 0.5, size=0.1) +
  geom_smooth(method = lm, se=F, color ="#e08214") +
  geom_ribbon(aes(ymin=lwr, ymax=upr, fill="#e08214"), alpha = 0.2) +
  ggtitle(samplename) +
  theme_bw() +
  geom_point(data=y_mers, aes(x= countF, y= countM, color = "y_mers"), alpha = 0.5, size=0.1) +
  geom_point(data=x_mers, aes(x= countF, y= countM, color = "x_mers"), alpha = 0.5, size=0.1) +
  geom_point(data=z_mers, aes(x= countF, y= countM, color = "z_mers"), alpha = 0.5, size=0.1) +
  geom_point(data=w_mers, aes(x= countF, y= countM, color = "w_mers"), alpha = 0.5, size=0.1) +
  scale_color_manual(name = "Kmer association",
                      values = c("y_mers" = "#053061", "x_mers" = "#b2182b", "z_mers" = "#2166ac", "w_mers"="#d6604d"),
  labels = c("y_mers","x_mers","z_mers","w_mers")) +
  scale_fill_identity()

The wrong plot:

这是错的,因为" y_mers"应该有" x_mers"," x_mers" " zmers"," zmers" " w_mers"和" w_mers"的颜色" y_mers"的颜色。

像这样: The correct order

0 个答案:

没有答案
相关问题