ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy))
As the increase of enjine displacement in litres, the trend of highway miles per gallon is decreasing.
Some of the points cannot be seen since the same data cause the overlap of the points
ggplot(mpg) +
geom_bar(mapping = aes(y = class, color = class))
answer: 2seater vehicle class contains least samples in the data
set.
ggplot(mpg) +
geom_bar(aes(y = manufacturer, fill = manufacturer))
answer: dodge, toyota, and volkswagen contains most samples in the data
set.
ggplot(mpg) +
geom_bar(mapping = aes(x = manufacturer, fill = class), position = "dodge")
answer: chevrolet, ford, and toyota produce most SUVs ### 2. Change the
keyword x in the aes function into y and reproduce the plot. What did
you see?
ggplot(mpg) +
geom_bar(mapping = aes(y = manufacturer, fill = class), position = "dodge")
answer: the names of manufacturers are not overlapped. The data is more
clearer now.
ggplot(data = mpg, mapping = aes(y = displ)) +
stat_boxplot(geom = "errorbar", width = 0.5) + # The "width" controls the line size
scale_x_discrete(breaks = NULL)
answer: empty whisker line
###2. Try to put the line of code geom_boxplot() before the stat_boxplot line and see what it gets.
ggplot(data = mpg, mapping = aes(y = displ)) +
geom_boxplot() +
stat_boxplot(geom = "errorbar", width = 0.5) + # The "width" controls the line size
scale_x_discrete(breaks = NULL)
answer: the whisker line is on the box plot
ggplot(mpg, mapping = aes(x = cty , y = manufacturer)) +
stat_boxplot(geom = "errorbar", width = 0.5) +
geom_boxplot()
answer: volkswagen is most fuel economic
answer: jeep is least fuel economic
answer: yes, it’s generally true for data beyond the current data set. but to be more accurate, we should consider more comprehensive data based on this.