首页 > 解决方案 > 如何使用 ggplot 更改组图例顺序

问题描述

我画了一个折线图。该图有 3 个组。我想更改 Legend 组的顺序。这是我的脚本

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

在此处输入图像描述

我想将标签更改为“LC: Exp”、“LC: Cubic”和“Max”。请建议我。

标签: rggplot2

解决方案


推荐阅读