z3tt / Z3tt

🔗 Source code of my homepage build with {blogdown}, HUGO and Netlify

Home Page:https://cedricscherer.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simpler labels

courtiol opened this issue · comments

Hi @z3tt,
There is one little thing that you may want to describe (which I find useful): it is possible to change the scale names using directly labs() without fiddling with the scale_ functions. It makes simple code more self consistent.

For example, instead of e.g.
https://github.com/Z3tt/Z3tt/blob/469531c7ce7460b103ee546b9e21bba0d80d8044/content/post/2019-08-05_ggplot2-tutorial.Rmd#L452-L459

I would probably write

ggplot(chic, aes(date, temp, color = factor(season))) + 
  geom_point() + 
  labs(x = "Year", y = "Temperature (°F)", color = "Seasons\nindicated\nby colors:") +  
  theme(legend.title = element_text(color = "chocolate",  
                                    size = 14, face = "bold"))

I did not run your code to check it, but I guess it should work and it should also work for fill, alpha... Of course if you aim at introducing scale_ step by step you may not want to use that here, but I think it is worth mentioning somewhere.
++

Hi Alex, thank you very much for that hint! You are right, it works and I remember that I used it once or twice but see or use it rarely nowadays. I've added it to the tutorial!