require(datasets)
require(ggplot2)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.3.2
require(ggthemes)
## Loading required package: ggthemes
## Warning: package 'ggthemes' was built under R version 3.3.2
Vis 1
mpg.plot <- ggplot(mpg)
mpg.plot +
geom_bar(aes(class,
fill = trans)) +
scale_fill_discrete(name = "Transmission")
Vis 2
mpg.plot +
geom_boxplot(aes(manufacturer, hwy)) +
theme_classic() +
coord_flip() +
labs(y = "Highway Fuel Efficiency (mile/gallon)",
x = "Vehicle Manufacturer")
Vis 3
ggplot(diamonds) +
geom_density(aes(price,
fill = cut,
color = cut),
alpha = 0.3,
size = 0.6) +
labs(title = "Diamond Price Density",
x = "Diamond Price (USD)",
y = "Density") +
theme_economist()
Vis 4
ggplot(iris,
aes(Sepal.Length, Petal.Length)) +
geom_point() +
geom_smooth(method = lm) +
theme_minimal() +
theme(panel.grid.major = element_line(size = 1),
panel.grid.minor = element_line(size = 0.7)) +
labs(title = "Relationship between Petal and Sepal Length",
x = "Iris Sepal Length",
y = "Iris Petal Length")
Vis 5
ggplot(iris,
aes(Sepal.Length,
Petal.Length,
color = Species)) +
geom_point() +
geom_smooth(method = lm, se = FALSE) +
theme_pander() +
theme(text = element_text(family = "serif"),
axis.ticks = element_line(color = "black",
size = 0.7),
legend.position = "bottom",
legend.title = element_text(face = "plain"),
plot.title = element_text(size = 14,
face = "plain")) +
labs(title = "Relationship between Petal and Sepal Length",
subtitle = "Species level comparison",
x = "Iris Sepal Length",
y = "Iris Petal Length")