Today we will create polished charts.
Welcome to Day 11 of “Viz with Me”!
Yesterday we made some bar plots
Goals for today:
Solutions for yesterday’s exercises.
Changing themes to create more polished looking charts.
island
variable in the palmerpenguins dataset. This is another categorical variable you can explore.Now this is a simple default bar plot. But what if you want to make it look more polished?
Themes in ggplot2 allow you to change the appearance of your plots. You can change the background, gridlines, text, and more.
Here are some popular themes you can use:
theme_minimal() - A minimalistic theme with no gridlines.
Let’s try this theme on our plot.
You can also try other themes like theme_light()
, theme_dark()
, theme_bw()
, etc. Let me know which one you like the best!
palmerpenguins
dataset. See if you can add labels and make a complete graph using what we’ve learned so far.penguins %>%
ggplot(aes(x = bill_length_mm, y = bill_depth_mm)) +
geom_point()+
labs(title = "Bill depth vs. Bill length",
x = "Bill length (mm)",
y = "Bill depth (mm)")
Let’s try changing the theme for this plot as well. But, we will use a different theme this time.
penguins %>%
ggplot(aes(x = bill_length_mm, y = bill_depth_mm)) +
geom_point()+
labs(title = "Bill depth vs. Bill length",
x = "Bill length (mm)",
y = "Bill depth (mm)")+
theme_classic()
How does this theme look?
Take a look at all the themes here which are part of the ggplot2 package. If you are fan of dark themes, check out the theme_dark()
.
If you are up to advancing your plots with more themes, try using the hrbrthemes
(Rudis 2024). It has a wide variety of themes to choose from.
I shall see you tomorrow with more exciting stuff!
For attribution, please cite this work as
Soundararajan (2024, Oct. 11). My R Space: Day 11 of viz with me. Retrieved from https://github.com/soundarya24/SoundBlog/posts/2024-10-10-day-11-of-viz-with-me/
BibTeX citation
@misc{soundararajan2024day, author = {Soundararajan, Soundarya}, title = {My R Space: Day 11 of viz with me}, url = {https://github.com/soundarya24/SoundBlog/posts/2024-10-10-day-11-of-viz-with-me/}, year = {2024} }