Day 5 of viz with me

Data viz Beginner ggplot scatterplot practice DataViz Challenge

Today we practice what we learnt so far.

Soundarya Soundararajan true
2024-10-05

Welcome to Day 5 of “Viz with Me”!

Goals for today: Today, let’s put into practice everything we have learned so far!

Exercise

Create a scatter plot using the Penguins dataset, with flipper length on the x-axis and body mass on the y-axis.

Steps

  1. Load the necessary libraries (hint: tidyverse, palmerpenguins).
  1. Call the penguins dataset.

  2. Pipe the data into ggplot to begin building your plot.

  3. 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).

  1. Don’t forget to add the + sign to connect your geom layer (scatter plot).

  2. 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:

Why do we call tidyverse even though we use ggplot?

There are 2 reasons why we call tidyverse even though we use ggplot.

  1. We used tidyverse because it includes the ggplot2 package, which we need to create our plots.

  2. 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.

Citation

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}
}