install.packages("gapminder")
ggplot(iris, aes(x = Petal.Length, y = Petal.Width)) +
geom_point(aes(color = Species))
ggplot(iris, aes(x = Petal.Length)) +
geom_histogram(aes(fill = Species), color = "black")
ggplot(iris, aes(x = Petal.Length)) +
geom_histogram(aes(fill = Species), color = "black", position = "dodge")
ggplot(iris, aes(x = Petal.Length)) +
geom_histogram(aes(fill = Species), color = "black", position = "identity")
ggplot(iris, aes(x = Petal.Length)) +
geom_histogram(aes(fill = Species),
color = "black",
position = "identity",
alpha = 0.7)
ggplot(iris, aes(x = Petal.Length)) +
geom_histogram(aes(fill = Species),
color = "black",
position = "identity",
alpha = 0.7,
bins = 15)
ggplot(iris, aes(x = Petal.Length)) +
geom_histogram(aes(fill = Species),
color = "black",
position = "identity",
alpha = 0.7,
bins = 50)
ggplot(iris, aes(x = Petal.Length)) +
geom_histogram(aes(fill = Species),
color = "black",
position = "identity",
alpha = 0.7,
bins = 25)
ggplot(iris, aes(x = Petal.Length)) +
geom_histogram(aes(fill = Species),
color = "black",
position = "identity",
alpha = 0.7,
bins = 25) +
facet_grid(Species~.)
ggplot(diamonds, aes(x = price)) +
geom_histogram(aes(fill = cut), color = "black") +
facet_grid(cut~.)
ggplot(diamonds, aes(x = price)) +
geom_histogram(aes(fill = cut), color = "black") +
facet_grid(cut~clarity)
ggplot(diamonds, aes(x = price)) +
geom_histogram(aes(fill = cut), color = "black") +
facet_grid(cut~., scales = "free_y")
ggplot(diamonds, aes(x = price)) +
geom_histogram(aes(fill = cut), color = "black") +
facet_grid(cut~., scales = "free_y") +
scale_x_log10()
ggplot(diamonds, aes(x = price)) +
geom_histogram(aes(fill = cut), color = "black") +
geom_freqpoly() +
facet_grid(cut~., scales = "free_y") +
scale_x_log10()
Computes and draws kernel density estimate, which is a smoothed version of the histogram. This is a useful alternative to the histogram for continuous data that comes from an underlying smooth distribution.
ggplot(diamonds, aes(x = price)) +
geom_density(aes(fill = cut)) +
facet_grid(cut~.) +
scale_x_log10()
ggplot(diamonds, aes(x = price)) +
geom_density(aes(fill = cut), alpha = 0.5) +
scale_x_log10()
ggplot(diamonds, aes(x = price)) +
geom_density(aes(fill = cut), alpha = 0.5, adjust = 2) +
scale_x_log10()
ggplot(diamonds, aes(x = price)) +
geom_density(aes(fill = cut), alpha = 0.5, adjust = .5) +
scale_x_log10()
ggplot(diamonds, aes(x = carat, y = price)) +
geom_bin2d()
ggplot(diamonds, aes(x = carat, y = price)) +
geom_bin2d() +
scale_fill_viridis_c()
ggplot(diamonds, aes(x = carat, y = price)) +
geom_bin2d() +
scale_fill_viridis_c(trans = "log")
ggplot(diamonds, aes(x = carat, y = price)) +
geom_bin2d() +
scale_fill_viridis_c(trans = "log", breaks = c(5, 50, 500, 5000))
ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) +
geom_bin2d() +
scale_x_log10()
ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) +
geom_bin2d() +
scale_x_log10() +
scale_fill_viridis_c()
ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) +
geom_bin2d() +
scale_x_log10() +
scale_fill_viridis_c() +
facet_wrap(~continent)
ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) +
geom_bin2d() +
geom_density2d() +
scale_x_log10() +
scale_fill_viridis_c()
ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) +
geom_density2d(aes(color = ..level..)) +
scale_x_log10()
ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) +
geom_density2d_filled() +
scale_x_log10()
ggplot(gapminder, aes(x = year, y = lifeExp)) +
geom_violin()
ggplot(gapminder, aes(x = factor(year), y = lifeExp)) +
geom_violin()
ggplot(gapminder, aes(x = factor(year), y = lifeExp)) +
geom_boxplot()
ggplot(gapminder, aes(x = factor(year), y = lifeExp)) +
geom_boxplot() +
geom_violin(fill = NA)
ggplot(gapminder, aes(x = factor(year), y = lifeExp, color = continent)) +
geom_boxplot() +
geom_violin(fill = NA) +
facet_grid(continent~.)
ggplot(gapminder, aes(x = factor(year), y = lifeExp, color = continent)) +
geom_boxplot() +
geom_violin(fill = NA) +
facet_grid(continent~.) +
labs(
x = "",
y = "Life Expectancy",
color = "Continent",
title = "Distribution of Life Expectancy",
subtitle = "1952-2007"
)