R-Studio Tutorial: Adding a custom legend to a plot with multiple elements

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ย. 2024

ความคิดเห็น • 18

  • @matthewholmes2803
    @matthewholmes2803 ปีที่แล้ว +5

    How can I change the name of the legend from "colour" to "population"?

  • @AnuragGaonkar9703
    @AnuragGaonkar9703 2 ปีที่แล้ว +3

    Thank you so much for uploading follow-up videos for legends. It helped me with my university assignment!!!!

  • @sofialeitao9815
    @sofialeitao9815 ปีที่แล้ว

    Thank so soooo much, I spent hours looking for a way to create a legend using my data and everywhere I looked they never explained how to addapt my data so that the coding works. Thank you :)

  • @michaelogunmakin9143
    @michaelogunmakin9143 ปีที่แล้ว

    Thanks, really helped solve an issue I had

  • @thatgoanguy4427
    @thatgoanguy4427 ปีที่แล้ว +1

    Legend doesn't appear automatically

  • @user-px7fy8hl7f
    @user-px7fy8hl7f 10 หลายเดือนก่อน

    Du bist ein banger!! Vielen Dank!

  • @remyxi
    @remyxi ปีที่แล้ว

    Thanks so much for this update! Its perfect and great that you optimize this, you rock mannn!

  • @weall8677
    @weall8677 2 ปีที่แล้ว

    it's so useful. Thanks so much

  • @rodrigofilipe5411
    @rodrigofilipe5411 2 ปีที่แล้ว

    Very helpfull, goood video!

  •  3 ปีที่แล้ว

    Thanks!

  • @sofialeitao9815
    @sofialeitao9815 ปีที่แล้ว

    I have a problem with my code. I used what you taught in this video and added this: +scale_color_discrete(name="Legenda", labels=c("Nº de gaivotas adultas","Nº de gaivotas juvenis", "Nº total de gaivotas")) to change the name of the tittle of the legend, but the colours I chose dissapeard and now it has the original automatic colours. How do I get the colours I want back??? Please help!

    • @DataGarden
      @DataGarden  ปีที่แล้ว +1

      Hey Sofia, can you maybe post your complete complete code here in the comment? Then I can have a look.
      Otherwise I suggest that using the code from the video and adding "+
      guides(color = guide_legend(title = "Legenda"))" might do what you are having in mind. Let me know if that works.

    • @sofialeitao9815
      @sofialeitao9815 ปีที่แล้ว

      @@DataGarden IT WORKED!!! Again, thank you so much :) Now how can I change the name of the labels (in the legend)?
      Here is my complete code:
      ggplot(data=X56195IolCle56163SofLei, mapping = aes(x=horas)) + geom_point (mapping =aes ( y=gadlt, color="gadlt")) + geom_point ( mapping = aes ( y=gjvnl, color="gjvnl"))+ geom_point ( mapping = aes( y=ngaiv, color="ngaiv"))+ labs ( title="Gráfico 1 - Variação de gaivotas ao longo do dia", x= "Tempo (min)", y= "Número de gaivotas")+ theme(plot.title = element_text(hjust = 0.5))+ guides( color = guide_legend ( title = "Legenda"))

    • @DataGarden
      @DataGarden  ปีที่แล้ว +1

      @@sofialeitao9815 Hey Sofia, that's nice! I think you should be able to change the names of the legend items in the scale_color_manual command such as the following
      +scale_color_manual(
      values = c("gadlt"="blue","gjvnl"="orange","ngaiv"="red"),
      labels=c("your value 1 here", "your value 2 here","your value 2 here"))
      Let me know if that works.

    • @sofialeitao9815
      @sofialeitao9815 ปีที่แล้ว

      @@DataGarden It worked :) Thank you for your time and help, I was really desperate.

  • @iaikitkuparlyngdoh3455
    @iaikitkuparlyngdoh3455 3 ปีที่แล้ว

    Can you create a video where we also change the shape of points and match them along with the legend?

    • @DataGarden
      @DataGarden  3 ปีที่แล้ว +1

      I think for that you have to change the structure of your data.frame to have only one variable with the values and another variable for the categories. That is actually how ggplot prefers to be fed. If you just change the shape in the plot as shown here, unfortunately there will be a misrepresentation in the legend. I will note your topic down for a future video and will get to it soon.

    • @iaikitkuparlyngdoh3455
      @iaikitkuparlyngdoh3455 3 ปีที่แล้ว

      @@DataGarden Thank you. It works 👍🏻