library(ggplot2)
library(gcookbook)
library(RColorBrewer)
options(scipen=999)
Problem 1
ggplot(mpg, aes(hwy)) +
geom_bar(aes(fill = drv), alpha = 0.5, width = 1) +
labs(
title = "Histogram",
subtitle = "Histogram of Highway Mile Per Gallon",
caption = "Source: mpg"
) +
theme_minimal()

Problem 2
ggplot(mpg, aes(hwy)) +
geom_bar(aes(fill = drv), alpha = 0.5, width = 1) +
facet_grid(drv~ .) +
scale_y_continuous(limits = c(0, 30)) +
labs(
title = "Histogram",
subtitle = "Histogram of Highway Mile Per Gallon",
caption = "Source: mpg"
) +
theme_minimal()

Problem 3
ggplot(midwest, aes(area, poptotal)) +
geom_point(aes(color = state, size = popdensity), alpha = 0.4) +
scale_x_continuous(name = "Area", limits = c(0, 0.1)) +
scale_y_continuous(name = "Population", limits = c(0, 500000)) +
geom_smooth(se = FALSE) +
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
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_point(aes(shape = Species, color = Species), size = 6, alpha = 0.5) +
theme_minimal() +
labs(
title = "Scatterplot",
subtitle = "Sepal.Length Vs Sepal.Width",
caption = "Source: iris"
)

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

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