我正在尝试更改图例标题和键标签以显示自定义信息。这就是我所拥有的。
这是我尝试的代码。
g + scale_fill_discrete(name="Experimental\nCondition",
breaks=c("IL,1","IN,1","MI,1","OH,1","WI,1","IL","IN","MI","OH","WI"),
labels=c("1","2","3","4","5","6","7","8","9","10"))
谢谢
答案 0 :(得分:0)
似乎OP
正在寻找一种方法,可以将colour
和fill
用于数据点,然后自定义自己选择的legend
。
在作为OP的一部分提供的示例中,最后“5”点使用与white
相同的颜色。在定义自定义fill
颜色时应该牢记这一点。
另一点是,只有shape
值大于20
的点才允许同时使用color
和fill
。这就是为什么shape
在下面的示例中被视为“22”的原因。
样本数据: 库(GGPLOT2)
df< - data.frame(A = 1:20,B =样本(30:40,20,TRUE),C =样本(1:10,20,TRUE))
ggplot(df, aes(A, B, colour = factor(C), fill = factor(C))) +
geom_point(alpha = 0.6, shape = 22, size = 4) +
scale_fill_manual(name="Experimental\nCondition",
values = c("gray","pink","coral","seagreen","ivory","white","white","white","white","white"),
labels=c("IL,1","IN,1","MI,1","OH,1","WI,1","IL","IN","MI","OH","WI"),
breaks=c("1","2","3","4","5","6","7","8","9","10")) +
scale_colour_manual(name="Experimental\nCondition",
values = c("red","green","yellow","blue","pink","ivory","gray","coral","seagreen","orange"),
labels=c("IL,1","IN,1","MI,1","OH,1","WI,1","IL","IN","MI","OH","WI"),
breaks=c("1","2","3","4","5","6","7","8","9","10"))