library(ggplot2)
ggplot(midwest, aes(x = percollege, colour = state)) +
geom_density() +
xlab("Percent College Educated") +
ylab("Density") +
ggtitle("Distribution of College Education by State")
This graph represents the distribution of the percentage of college
educated residents across counties in five Midwestern states. Most
counties fall between about 10% and 20% college educated. The
distribuions are also skewed to the right, therefore there is a smaller
number of counties have much higher percentages of college-educated
residents.
ggplot(data = mpg, aes(x = cty)) +
geom_histogram() +
xlab("City Fuel Economy (MPG)") +
ylab("Number of Vehicles") +
ggtitle("Distribution of City Fuel Economy")
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.
This shows the distribution of city fuel economy for the vehicles in the
mpg dataset. Most of the vehicles have city fuel economy between
approximately 12 and 20 MPG, while very few have high city MPG.
One of the weaknesses is that the appearance depends on the width and number of histogram bins.
ggplot(mpg, aes(x = class, y = hwy)) +
geom_boxplot() +
xlab("Vehicle Class") +
ylab("Highway Fuel Economy (MPG)") +
ggtitle("Highway Fuel Economy by Vehicle Class")
The boxplot is comparing highway fuel economy across different vehicle
classes. Compact, midsize, and subcompact vehicles have higher highway
MPG. Pickups and SUVs tend to have lower highway MPG. There are also
outliers.
One of the weaknesses is that it does not show every individual vehicle, so it is difficult to see how many observations are within each class.
ggplot(mpg, aes(x = class, y = hwy)) +
geom_violin() +
xlab("Vehicle Class") +
ylab("Highway Fuel Economy (MPG)") +
ggtitle("Distribution of Highway Fuel Economy by Vehicle Class")
This plot showw wider portions of each violin representing the MPG
values where more vehicles are concentrated. It shows that the highway
MPG varies considerably across vehicle classes.
The violin plots weakness is that it does not clearly display the exact values (median or quartiles). This makes comparing between vehicle classes more difficult that with a boxplot.
ggplot(mpg, aes(x = hwy)) +
geom_density() +
xlab("Highway Fuel Economy (MPG)") +
ylab("Density") +
ggtitle("Distribution of Highway Fuel Economy")
In this plot, there are concentrations of vehicles around the upper
teens and the mid-to-upper 20s MPG, while few vehicles have highway fuel
economy above approximately 35 MPG.
This gragh displays density rather than the actual number of vehicles so it is difficult to determine how many observations fall within a certain MPG range.
ggplot(mpg, aes(x = displ, y = hwy)) +
geom_point() +
xlab("Engine Displacement (Liters)") +
ylab("Highway Fuel Economy (MPG)") +
ggtitle("Engine Size and Highway Fuel Economy")
The plot shows a negative relationship between engine displacement and
highway fuel economy. As the engine displacement increases, highway MPG
generally decrease. Vehicles with smaller engines tend to have better
highway fuel economy.
Serveral of the data points are overlapping because there are vehicles that are similar regarding engine displacement and highway MPG values. This makes it difficult to determine the number of vehicles that are overlapping.