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.
Exercise
Your turn! Replace x = mpg
with x = wt
and see what happens.
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.
Making a Scatter Plot
Let’s make it pretty by adding a title, a subtitle, changing the color of the points.
Exercise
Your turn, change the x and y variables to hp
and mpg
and see what happens.
Loading...
Sections in this course
A Beginner's Introduction to R Through the Tidyverse