change both legend titles in a ggplot with two legends

前端 未结 2 1240
走了就别回头了
走了就别回头了 2020-11-29 03:03

I have two legends on my ggplot with two different legend titles (automatically created from ggplot()). Now, I want to change this legend titles. + labs(

相关标签:
2条回答
  • 2020-11-29 03:14

    If I understood your point correctly, you can simply use + labs(shape = "shape legend title", colour = "colour legend title")

    0 讨论(0)
  • 2020-11-29 03:39

    Here is an example using the iris dataset:

    data(iris)
    ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) +
        geom_point(aes(shape=Species, colour=Petal.Width)) + 
        scale_colour_gradient() +
        labs(shape="Species label", colour="Petal width label")
    

    You specify the labels using labs(), with each scale separately specified, i.e. labs(shape="Species label", colour="Petal width label").

    enter image description here

    0 讨论(0)
提交回复
热议问题