在下图中:
library(ggplot2)
test <- data.frame(Depth=c(rep(c(0,10,20),4)),
Core=c(rep("A", 6), rep("B",6)),
Variable=c(rep("Treat1",3),rep("Treat2",3), rep("Treat1",3),rep("Treat2",3)),
Value=runif(12,0,1))
ggplot(test, aes(Value, Depth, col=Variable, shape=Core, lty=Core))+
geom_path(aes(group=interaction(Variable, Core))) +
geom_point(aes(group=interaction(Variable, Core)))+
theme_bw()+
guides(colour = guide_legend(aes.override=list(linetype = "solid")))
是否可以从基于颜色的图例中删除形状(设置为“变量”),就像我在aes.overide
中尝试使用guides
一样?
我想从左边的图例中删除形状;实际上我想用填充框替换当前的图例键(线条和形状)。由于aes包含交互参数,我担心我通过colour=guide_legend
操纵图例的尝试是徒劳的。
答案 0 :(得分:2)
在您指定override.aes
,aes.override
(框)的地方使用linetype = 0
代替shape = 15
:
ggplot(test, aes(Value, Depth,
color = Variable, shape = Core, lty = Core))+
geom_path(aes(group = interaction(Variable, Core))) +
geom_point(aes(group = interaction(Variable, Core)))+
theme_bw()+
guides(colour = guide_legend(override.aes=list(shape = 15, size = 5, linetype = 0)))
结果: