Day 3 of viz with me

Data viz Beginner ggplot scatterplot geom_point DataViz Challenge

Time for your first plot—don’t forget to celebrate!

Soundarya Soundararajan true
2024-10-03

Welcome to Day 3 of Viz with Me!

Goals for today: Draw a simple scatterplot and celebrate your first win!

Recap

By now, your script might look something like this:

This code creates a canvas, which is a great start. Today, we will explore geoms. Geom stands for geometry, which defines the visual representation of your data. For a scatterplot, we simply need points to represent the data points. The corresponding geom for this is geom_point().

Scatterplot

Let’s introduce geom_point() to the script. However, instead of using the pipe (%>%) here, we’ll use the + symbol.

Why not use the pipe here? This is because the pipe is used to link your data to ggplot(). In the future, if you clean or filter the data before plotting, the pipe will be useful. But once ggplot() is initiated, all the customizations (like adding geoms) are done using +.

Did you run the library() functions earlier from your script? If not, run them now. Otherwise, the following code will not work.

Here’s the updated code:

penguins %>%
  ggplot(aes(x = bill_length_mm, y = body_mass_g)) +
  geom_point()

Voila!

You’ve created your first scatterplot.

Summary

All we needed were three things to create our plot:

  1. Data

  2. A coordinate system – to specify x and y using the aes() function in ggplot()

  3. A geom – in this case, geom_point()

Remember these three key elements: Data, coordinate system, and geom. Repeat after me: Data, coordinate system, and geom.

You have mastered the basic formula for ggplot(), and now, you can create wonders from here on!

For today, enjoy creating your scatterplot and don’t forget to save your script!

I still remember the excitement of creating my first ggplot()! We’ll continue to refine this plot with titles, axes, and more over the coming days.

Time to celebrate both Navratri and your first plot—what a perfect reason to dance! Here’s a little virtual spin and twirl from me in celebration of your progress and the festive spirit. Keep up the great work, and keep the celebrations going! 🎉💃🕺🎶

Dance like a child as if no one is watching!

And jump here to day 4 of the series to learn adding titles and axes names

Citation

For attribution, please cite this work as

Soundararajan (2024, Oct. 3). My R Space: Day 3 of viz with me. Retrieved from https://github.com/soundarya24/SoundBlog/posts/2024-10-03-day-3-of-viz-with-me/

BibTeX citation

@misc{soundararajan2024day,
  author = {Soundararajan, Soundarya},
  title = {My R Space: Day 3 of viz with me},
  url = {https://github.com/soundarya24/SoundBlog/posts/2024-10-03-day-3-of-viz-with-me/},
  year = {2024}
}