Introduction
R has powerful and aesthetic graphics capabilities. In this blog entry, you’ll learn how to use jittered points in R graphics created with ggplot.
Access Data and Libraries
Install ggplot if you have not already done so, and load ggplot2:
install.packages("ggplot")
library(ggplot2)
Create Some Scatter Plots
library(ggplot2)
scatter <- ggplot(mpg, aes(cyl, hwy))
scatter + geom_point(colour="firebrick")
Here’s the first scatterplot you generated:
Here’s why this scatterplot isn’t very useful. Because of the limited number of cylinders in the dataset, you don’t really get a good idea of the spread of the variables. Using a jittered points command makes the underlying distribution easier to visualize:
scatter + geom_jitter(colour="cadetblue1")
Adding randomness to the placement of the variables makes this scatterplot more informative. Finally, let’s relabel it:
new <- scatter + geom_jitter(colour="cadetblue1")
new + labs(title="Highway MPG by Cylinder Number", subtitle="From R's mpg dataset", y="Highway MPG", x="Cylinders")
Here’s what you get:
That’s what you wanted.
BridgeText can help you with all of your statistical analysis needs.