Today, we will explore going beyond using colors to represent groups.
Welcome to Day 7 of “Viz with Me”!
Yesterday, we learnt how to use colors to represent groups in a plot.
Goals for today: Instead of using colors to differentiate the groups in a plot, are there other ways to do so?
Yes! There are two additional methods:
Changing the shape of the groups.
Plotting the groups separately.
Today, we’ll focus on the first method: changing the shape.
Here’s an example:
library(tidyverse)
library(palmerpenguins)
penguins %>%
ggplot(aes(bill_length_mm, body_mass_g)) +
geom_point(aes(shape = species))
In this plot, instead of using colors, we are using shape to differentiate between the three species of penguins. If you’d like, you can also add colors to the plot like this:
penguins %>%
ggplot(aes(bill_length_mm, body_mass_g)) +
geom_point(aes(shape = species, color = species))
Sometimes, we do not want to use colors in our plots but still need a way to differentiate the groups, especially in scatter plots. This method of using shapes is a great alternative.
Alright, that’s all for today! I’ll see you tomorrow with another type of chart. Don’t forget to save your script for today’s lesson!
Jump to day 8 of “Viz with Me” here.
For attribution, please cite this work as
Soundararajan (2024, Oct. 7). My R Space: Day 7 of viz with me. Retrieved from https://github.com/soundarya24/SoundBlog/posts/2024-10-07-day-7-of-viz-with-me/
BibTeX citation
@misc{soundararajan2024day, author = {Soundararajan, Soundarya}, title = {My R Space: Day 7 of viz with me}, url = {https://github.com/soundarya24/SoundBlog/posts/2024-10-07-day-7-of-viz-with-me/}, year = {2024} }