Today we practice what we learnt so far.
Welcome to Day 5 of “Viz with Me”!
Goals for today: Today, let’s put into practice everything we have learned so far!
Create a scatter plot using the Penguins dataset, with flipper length on the x-axis and body mass on the y-axis.
tidyverse
, palmerpenguins
).Call the penguins dataset.
Pipe the data into ggplot
to begin building your plot.
Inside ggplot()
, use the aes()
function to map the x and y variables correctly
Tip: You can check the variable names by running names(penguins).
Don’t forget to add the +
sign to connect your geom layer (scatter plot).
Use the labs()
function to add your preferred title, axis labels, subtitle, and caption.
Today, I’m only sharing the output for you to match, not the full code. Tomorrow, I’ll provide the solution.
Here’s what your output should look like:
There are 2 reasons why we call tidyverse even though we use ggplot.
We used tidyverse
because it includes the ggplot2
package, which we need to create our plots.
We use pipe operator to make the code more readable and easier to follow. That comes from the magrittr
package, which is part of the tidyverse.
If we have used library(ggplot2)
instead of library(tidyverse)
, we would have to load library(magrittr)
separately to use the pipe operator.
That’s all for today! Keep practicing, and I’ll see you tomorrow with the solution!
Jump here for the solution to the challenge and on adding colors.
For attribution, please cite this work as
Soundararajan (2024, Oct. 5). My R Space: Day 5 of viz with me. Retrieved from https://github.com/soundarya24/SoundBlog/posts/2024-10-05-day-5-of-viz-with-me/
BibTeX citation
@misc{soundararajan2024day, author = {Soundararajan, Soundarya}, title = {My R Space: Day 5 of viz with me}, url = {https://github.com/soundarya24/SoundBlog/posts/2024-10-05-day-5-of-viz-with-me/}, year = {2024} }