##Problem 1
library(ggplot2)
ggplot(mpg, aes(hwy, fill = drv)) + geom_histogram(alpha = 0.5) + theme_minimal() + labs(title = "Histogram", subtitle = "Histogram of Highway Mile Per Gallon", caption = "Source: mpg")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
##Problem 2
library(ggplot2)
ggplot(mpg, aes(hwy, fill = drv)) + geom_histogram(alpha = 0.5) + facet_grid(rows = vars(drv)) + theme_minimal() + labs(title = "Histogram using facet_grid()", subtitle = "Histogram of Highway Mile Per Gallon", caption = "Source: mpg")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
##Problem 3
library(ggplot2)
options(scipen = 999)
ggplot(midwest, aes(area, poptotal)) + geom_point(aes(color = state, size = popdensity), alpha = 0.5) + geom_smooth(se = FALSE) + xlim(c(0, 0.1)) + ylim(c(0, 500000)) + theme_classic() + labs(title = "Scatterplot", subtitle = "Area Vs Population", caption = "Source: midwest")
## `geom_smooth()` using method = 'loess' and 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(iris, aes(Sepal.Length, Sepal.Width, color = Species, shape = Species)) + geom_point(size = 6, alpha = 0.5) + theme_minimal() + labs(title = "Scatterplot", subtitle = "Sepal.Length Vs Sepal.Width", caption = "Source: iris")
##Problem 5
library(gcookbook)
ggplot(heightweight, aes(heightIn, weightLb, color = sex)) + geom_point(size = 3, alpha = 0.5) + geom_smooth(method = lm, se = FALSE) + theme_classic() + labs(title = "Scatterplot", subtitle = "Weight Vs Height", caption = "Source: heightweight")
## `geom_smooth()` using formula 'y ~ x'
##Problem 6
library(ggplot2)
library(RColorBrewer)
ggplot(mpg, aes(manufacturer, fill = class)) + geom_bar(width = 0.5) + theme_minimal() + theme(axis.text.x = element_text(angle = 65, hjust = 1)) + scale_fill_brewer(palette = "Spectral") + labs(title = "Barplot", subtitle = "Manufacturer across Vehicle Classes")