Home > OS >  How do i change the legend title for this ggplot in r?
How do i change the legend title for this ggplot in r?

Time:11-06

i am having difficulty changing the legend title of this plot which shouldn't be that difficult. . .

The code looks like this:

p2<-lf_data |> subset(grepl("^. (gfp)$",media)) |>
  #  filter(row_number() %% 3 == 1) %>%
  ggplot(aes(time, gfp, colour = media,fill=media))  
  geom_smooth(method="loess",span=0.2)  
  # geom_point(method="loess",alpha=0.4)  
  labs(title="GFP time series of species and media",y="GFP [RFU]",x="Time (h)") 
  theme(text = element_text(size = 15),
        legend.position="bottom")
  )

Which gives a plot that looks like this:

enter image description here

Every attempt i've made trying to change the title, the legend seperates the fill and the line and i get two seperate titles.

So, my question is simply this: How can i change the legend title which currently is just "media" to something different?

Thanks a lot in advance!

CodePudding user response:

Solved by stefans comment, using:

labs(..., fill = "MYTITLE", color = "MYTITLE")
  • Related