Plotting Data Using ggplot2
Learn to make unique and professional-quality bar plots with ggplot2.
Making a barplot in ggplot2
We’ll use the ggplot()
function. Notice that the function name does not contain the 2
on end, which the package ggplot2 has. There are many aspects that are similar to building the figure in base graphics, but several that are not. We will only go over the basics of figure making with ggplot2 here.
The initial setup to make a bar plot is a little more complicated in ggplot()
than in barplot2()
, but the result is more visually appealing. Moreover, plotting with ggplot2 requires a little more code than when plotting with base graphics.
- First, we must define where our data is found (
data=RP.means
). - Next, we must explain aesthetics. This is where we state which data will go on the x-axis and y-axis and which variable we want to fill in our bars with color. The aesthetics all go within a function called
aes()
.
One of the things that can be difficult to wrap our head around when plotting with ...