Problem 1

library(ggplot2)
ggplot(data=mpg, aes(x=hwy, fill=drv)) + geom_histogram (alpha=0.5) + theme_minimal() + labs(title="Histogram", subtitle="Histogram of Highway Per Gallon", caption="Source: mpg")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Problem 2

library(ggplot2)
ggplot (data=mpg, aes (x=hwy, fill=drv)) + geom_histogram (alpha=0.5) + theme_minimal() + facet_grid (rows=vars(drv)) + labs(title="Histogram using facet_grid()", subtitle="Histogram of Highway Per Gallon", caption="Source: mpg")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Problem 3

library(ggplot2)
options(scipen = 999)
ggplot (data = midwest, aes (x = area, y = poptotal)) + geom_point (alpha = 0.4, aes (color = state, size = popdensity)) + scale_x_continuous (limits = c (0, 0.1)) + scale_y_continuous (limits = c (0, 500000)) + geom_smooth (se = FALSE, method = loess) + theme_classic()+ labs (title = "Scatterplot", subtitle = "Area vs Population", caption ="Source: midwest", x= "Area", y= "Population")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (stat_smooth).
## Warning: Removed 15 rows containing missing values (geom_point).

Problem 4

library(ggplot2)
ggplot (data = iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point (alpha = 0.5, size = 6, aes (color = Species, shape = Species)) + theme_minimal() + labs (title = "Scatterplot", subtitle = "Sepal.Length vs Sepal.Width", caption ="Source: iris")

Problem 5

library(gcookbook)
ggplot (data = heightweight, aes (x = heightIn, y = weightLb, color = sex)) + geom_point (alpha = 0.5, size = 3) + geom_smooth (se = FALSE, method = "lm") + theme_classic() + labs (title = "Scatterplot", subtitle = "Weight vs Height", caption ="Source: heightweight")
## `geom_smooth()` using formula 'y ~ x'

Problem 6

library(ggplot2)
ggplot (data = mpg, aes (x = manufacturer, fill = class)) + theme_minimal() + geom_bar (width = 0.5) + scale_fill_brewer (palette = "Spectral") + theme (axis.text.x = element_text (angle = 65, hjust = 1)) + labs (title = "Barplot", subtitle = "Manufacturer across Vehicle Classes")