library(datasets)
library(ggthemes)
library(ggplot2)
Vis1
mpg.plot <- ggplot(mpg)
mpg.plot +
geom_bar(aes(class,
fill = trans)) +
scale_fill_discrete(name = "Transmission")
mpg.plot +
geom_boxplot(aes(manufacturer, hwy)) +
theme_classic() +
coord_flip() +
labs(y = "Highway Fuel Efficiency (mile/gallon)",
x = "Vehicle Manufacturer")
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()
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")
ggplot(iris, ## Create plot for iris dataset
aes(Sepal.Length, ## Set x-axis: sepal length
Petal.Length, ## Set y-axis: petal length
color = Species)) + ## Set legend: species. Use colors to differentiate.
geom_point() + ## Use scatter plot
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")