Problem Set 3 - Replicating pre-conceptualized graphs
Vis 1
ggplot(mpg, aes(x=factor(class), fill = factor(trans))) +
geom_bar() +
labs(title = "Number of Cars by Class and Transmission") + xlab ("Class") + ylab("Number of Cars") +
theme_bw() +
guides(fill=guide_legend(title="Transmission"))

Vis 2
ggplot (mpg, aes(manufacturer, hwy)) + geom_boxplot() + coord_flip() +
labs(title = "Box plot of Fuel Efficiency by Manufacturer") + ylab ("Highway Fuel Efficiency (miles/gallon)") + xlab("Vehicle Manufacturer") +
theme_bw()

Vis 3
ggplot(diamonds, aes(price)) +
geom_density(aes(group=cut, colour=cut, fill=cut), alpha=0.2) +
labs(title = "Diamond Price Density") + xlab ("Diamond Price (USD)") + ylab("Density") +
theme_economist()

Vis 4
ggplot(iris, aes(x=Sepal.Length, y=Petal.Length)) +
xlab ("Iris Sepal Length") + ylab ("Iris Petal Length") +
geom_point() +
ggtitle("Relationship between Petal and Sepal Length") +
geom_smooth(method = 'lm', formula = y ~ x) +
theme_bw()

Vis 5
ggplot(iris, aes(Sepal.Length, Petal.Length, color = Species)) +
xlab ("Iris Sepal Length") + ylab ("Iris Petal Length") +
geom_point() +
labs (title ="Relationship between Petal and Sepal Length", subtitle= "Species level comparision") +
geom_smooth(method = 'lm', formula = y ~ x) +
theme_bw() +
theme(legend.position="bottom")
