如何编辑图例标题和标签?

问题描述 投票:0回答:1

[第一篇文章,希望我已经包括了所有内容。

我正在尝试在下表中做两件事:

将图例标题从z,z1,z2更改为POS,ROD,INS

将图例标签全部更改为AOK和TUR

我整天都在努力寻找答案,到目前为止没有任何效果。

Plot

我的数据是:

Year Area   Percentage
  <dbl> <fct>       <dbl>
1  2008 AOKPOS      0.571
2  2008 AOKPOS      0.6  
3  2008 AOKPOS      0.5  
4  2008 AOKPOS      0.846
5  2008 AOKPOS      0.2  
6  2008 AOKPOS      0.625

我的代码是:

plot1<-ggplot() +
    # blue plot
    scale_x_continuous(name="", limits = c(2008, 2019),breaks = 0:2100)+ #No X axis title
    scale_y_continuous(name = "",labels = scales::percent)+ theme(text = element_text(size=10))+
    coord_cartesian(ylim = c(0,1))+
    geom_smooth(data=Possum, aes(x=x, y=y, group=z, colour=z), size=1)

plot1

plot2<-ggplot() +
    # blue plot
    scale_x_continuous(name="", limits = c(2008, 2019), breaks = 0:2100)+ #No X axis title
    scale_y_continuous(name = "",labels = scales::percent)+ theme(text = element_text(size=10))+
    coord_cartesian(ylim = c(0,1))+
    geom_smooth(data=Rodent, aes(x=x1, y=y1, group=z1, colour=z1), size=1)

plot2

plot3<-ggplot() +
    # blue plot
    scale_x_continuous(name="", limits = c(2008, 2019), breaks = 0:2100)+ #No X axis title
    scale_y_continuous(name = "",labels = scales::percent)+ theme(text = element_text(size=10))+
    coord_cartesian(ylim = c(0,1))+
    geom_smooth(data=Insect, aes(x=x2, y=y2, group=z2, colour=z2), size=1)

plot3

grid.arrange(plot1,plot2,plot3, nrow=3)
ggplot2 label legend title
1个回答
0
投票

我不知道您想如何更改它,但您可以像这样使用labs()函数来做到这一点

#Default plot
print(p)

#Modify legend titles
p + labs(fill = "Dose (mg)")

enter image description here

使用代码后,标题会像这样更改enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.