2

In the following plot:

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")))

is it possible with remove the shapes from the colour-based legend (set to "Variable"), as i tried with aes.overide in guides?

My real life example produces this legend: enter image description here

and I want to remove the shapes from the left legend; in fact I want to replace the current legend keys (lines and shapes) with filled boxes. Since the aes contains an interaction-argument, I fear my attempt to manipulate the legend via colour=guide_legend is futile.

pogibas
  • 27,303
  • 19
  • 84
  • 117
nouse
  • 3,315
  • 2
  • 29
  • 56
  • 1
    Might be helpful: [link1](https://stackoverflow.com/a/49377292/786542) & [link2](https://stackoverflow.com/a/37158908/786542) – Tung Mar 20 '18 at 16:56

1 Answers1

2

Use override.aes instead of aes.override where you specify linetype = 0, shape = 15 (boxes):

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)))

Result:

enter image description here

pogibas
  • 27,303
  • 19
  • 84
  • 117