Title: How do I edit the legend title and labels?
Tags: r;ggplot2
Question: First post so hopefully I've included everything. 

I'm trying to do two things on the below charts:


Change the legend title from z,z1,z2 to POS, ROD, INS
Change the legend labels all to AOK and TUR


I've been trying to find the answer all day and so far nothing has worked. 



My data is:

```Year Area   Percentage
  <dbl&gt; <fct&gt;       <dbl&gt;
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
```

My code is:

```plot1 <- ggplot() +
    # blue plot
    scale_x_continuous(name="", limits = c(2008, 2019),breaks = 0:2100)+ #No X axis title
    scale_y_continuous(name = "",labels = scales181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16percent)+ 
    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 = scales181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16percent)+ 
    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 = scales181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16percent)+ 
    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)
```



Here is another answer: I don't know how you want to change it but 
you can use labs() function to do that like so 

```#Default plot
print(p)

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



after using the code the title is change like this


Comment for this answer: Welcome to SO, the provided data doesn't seem to reflect the plot in the linked image. For the legend title try 
```+ labs(fill="POS")``` to plot1 and so forth. For the legend labels you could change the Area factor levels. It will be good to have a minimal reprex (See [here][1]). You seem to have a 4th variable (possum, rodent and insect) not available in the data.


  [1]: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610

Here is another answer: Ok, so shortly after posting I managed to figure it out:

```    plot1<-ggplot() +
    scale_x_continuous(name="", limits = c(2008, 2019),breaks = 0:2100)+ #No X axis title
    scale_y_continuous(name = "",labels = scales181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16percent)+ 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), name = "Possum",size=1)

plot1<- plot1 + scale_color_discrete(name="Pos", label=c("Aok","Tur"))

plot1

plot2<-ggplot() +
    scale_x_continuous(name="", limits = c(2008, 2019), breaks = 0:2100)+ #No X axis title
    scale_y_continuous(name = "",labels = scales181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16percent)+ 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<- plot2 + scale_color_discrete(name="Rod", label=c("Aok","Tur"))

plot2

plot3<-ggplot() +
    scale_x_continuous(name="", limits = c(2008, 2019), breaks = 0:2100)+ #No X axis title
    scale_y_continuous(name = "",labels = scales181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16percent)+ 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<- plot3 + scale_color_discrete(name="Ins",label=c("Aok","Tur"))

plot3

grid.arrange(plot1,plot2,plot3, nrow=3)
```


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:11/26/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<r><ggplot2>', 'Title': 'How do I edit the legend title and labels?', 'ViewCount': 58, 'id': 59043162, 'user_AboutMe': None, 'user_AccountId': 17169709.0, 'user_DisplayName': 'Andy McKay', 'user_Reputation': 11.0, 'user_Views': 1.0, 'user_id': 12427079.0}}