0

I plotted a line graph. This graph has 3 groups. I want to change the order of the Legend group. This is my script

dummy_plot = ggplot(data = dataplot , aes(x = factor(indexsampling),group = method)) +
geom_line(aes( y = value,linetype = method,color=method),size=1)+
geom_point(aes( y = value,shape=method,color=method))+

theme(plot.title = element_text(hjust = 0.5),
      text = element_text(size=20),
      axis.text=element_text(size=18),
      legend.text=element_text(size=18),
      legend.title=element_blank(),
      legend.position = c(1, 0.5),
      legend.justification = c(1, 0),
      legend.background = element_rect(fill=alpha('white', 0.0))
)+
labs(title = title_name ,x = xlabel,y=ylabel,fill="")+
scale_linetype_manual(values=c("dotted", "twodash","solid"))+
scale_x_discrete( labels = c('0.625',"0.500","0.333","0.288"))+
scale_y_continuous(limits = c(0.2,0.62))

enter image description here

I would like to change the label to "LC: Exp","LC: Cubic"and "Max". please suggest me.

Pisit Nakjai
  • 141
  • 1
  • 1
  • 10
  • 1
    Have you tried changing the order of your factor levels for your grouping variable? –  Jun 23 '19 at 07:45
  • If `method` is a factor, reorder its levels. Try, for instance, `with(dataplot, relevel(method, ref = 'LC: Exp'))`. – Rui Barradas Jun 23 '19 at 07:45
  • 1
    Thank you all, The first time I found this post "ggplot legends - change labels, order and title" but It doesn't solve my problem. That was my mistake, I didn't change a dataset before I plot it ( I used an old dataset). When I change to a new dataset it work. – Pisit Nakjai Jun 23 '19 at 08:36

0 Answers0