When you have two continuous variables and want to see their relationship, you’d draw a scatterplot by putting one variable on the x-axis and the other variable on the y-axis. In this post, we’ll look at how to draw scatterplots using the
mk_scatterplot() function from the ezplot package. We’ll also use the
scale_axis() function, which allows us to easily change the scale of the x-axis or y-axis. Let’s get started.
- Install a set of development tools
- Install devtools by running
Install and Load ezplot
The ezplot package comes with a films dataset containing the annual boxoffice/budget ratio between 1913 and 2014. We want to see how boxoffice is related to budget. We can make a scatterplot by putting boxoffice on the y-axis and budget on the x-axis.
It might be more informative if we use log10 scale instead.
Note we also changed the transparency and size of the points by passing values to the
pt_size arguments. And we added a regression line by setting
add_line=T and gave it a narrower width by setting
Finally, the dataset contains a variable called “made_money”, indicating if a film made money or not. We can use it to separate the points into two groups, where each group has its own regression line.
See how easy it is? All we need is to pass the name of the grouping variable,
“made_money”, to the
I created ezplot because there are too many detailed commands to remember when making and customizing a ggplot. If ezplot has improved your productivity, please tell your friends about it. In addition, I’m writing a book called ezplot: How to Easily Make ggplot2 Graphics for Data Analysis, and it is 20% complete. Read the sample chapters for FREE and get notified when the book is published.