How to remove the lines in the legend

I’m trying to remove the legend of lines, but I don’t know why it can’t remove, and I only want to keep the points of "supp".

library(ggpubr)    
a<-ggline(ToothGrowth, x = "dose", y = "len", 
           add = c("mean_se", "jitter"),
           color = "supp", palette = "jco")

b<-ggline(ToothGrowth, x = "dose", y = "len", 
           add = c("mean_se", "jitter"),
           color = "supp", palette = "jco")

ggarrange(plot_grid(a + theme(legend.position="none")), b,common.legend = TRUE, labels = c("A", "B"),legend = "right")

>Solution :

If you want to remove the lines from the legend and keep the points, you could use guides and override the linetype like this:

library(ggpubr)    
#> Loading required package: ggplot2
ggline(ToothGrowth, x = "dose", y = "len", 
       add = c("mean_se", "jitter"),
       color = "supp", palette = "jco") +
  guides(color = guide_legend(override.aes = list(linetype = 0)))

Created on 2022-11-25 with reprex v2.0.2


Code to comment:

library(ggpubr)  
library(cowplot)

a<-ggline(ToothGrowth, x = "dose", y = "len", 
          add = c("mean_se", "jitter"),
          color = "supp", palette = "jco")

b<-ggline(ToothGrowth, x = "dose", y = "len", 
          add = c("mean_se", "jitter"),
          color = "supp", palette = "jco")

ggarrange(plot_grid(a + theme(legend.position="none")), 
          b + guides(color = guide_legend(override.aes = list(linetype = 0))), 
          common.legend = TRUE, 
          labels = c("A", "B"),
          legend = "right")

Created on 2022-11-25 with reprex v2.0.2

Leave a Reply