自定义ggplot图例和自动颜色

时间:2017-04-11 13:55:03

标签: r ggplot2

我的情节看起来像这样:

enter image description here

library(ggplot2)
ggplot(data = dat, aes(x = value,
                             y = ..density..,
                             fill = exp_ID,
                             color = exp_ID)) +      
geom_density(alpha = 0.3,
             bw = 0.5) +
scale_x_log10(limits = c(0.0001,30000)) +
theme_classic(base_size = 15) +
theme(axis.text = element_text(color = "black")) +

scale_fill_discrete(name="Experimental\nCondition",
                    breaks=c("A", "B", "C", "D"),
                    labels=c("label1", "label2", "label3", "label4"))

添加自定义图例只能给我两个传说。我似乎无法删除自动的例如theme(legend.position="none"),因为这显然会删除它们,无论它放在代码中的哪个位置。

如何删除第一个图例?

此处的数据:https://drive.google.com/open?id=0B8piwdBM2UI5Sk03SU1XVUloQ0E

1 个答案:

答案 0 :(得分:0)

您需要做的是删除由aes规范自动创建的特定主题。为此,请添加以下行:

scale_fill(guide = 'none')

代码。在其他时候,你可能需要为你添加到你的情节中的其他美学做这件事。在这种情况下,只需使用适当的scale_命令

相关问题