A Beginner's Introduction to R Through the Tidyverse

Section 3 of 5

Visualizing Data

There is beauty in visualizing data. A form of visual grammar turns data into insight, just like how grammar gives life to words.

Making a Bar Chart

In tidyverse, there is a function called ggplot which helps us to create charts.

The ggplot function takes in two arguments: data and mapping. We pass an aesthetic or aes() inside mapping. And then inside aes() we add our x and y variables.

Bar Chart

Exercise

Your turn! Replace x = mpg with x = wt and see what happens.

Bar Chart

Let’s make it pretty by removing the grid lines, adding a title, changing the color of the bars, reordering the bars, keeping the names in the y axis, and moving the x-axis label to the top.

Bar Chart

Making a Scatter Plot

Scatter Plot

Let’s make it pretty by adding a title, a subtitle, changing the color of the points.

Scatter Plot

Exercise

Your turn, change the x and y variables to hp and mpg and see what happens.

Scatter Plot

Loading...

Go to Next Section Summarising Data →

Sections in this course

A Beginner's Introduction to R Through the Tidyverse

0%0/9