install.packages("palmerpenguins")
Descriptive Statistics
Kyiv School of Economics
palmerpenguins
# A tibble: 6 × 8
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
<fct> <fct> <dbl> <dbl> <int> <int>
1 Adelie Torgersen 39.1 18.7 181 3750
2 Adelie Torgersen 39.5 17.4 186 3800
3 Adelie Torgersen 40.3 18 195 3250
4 Adelie Torgersen NA NA NA NA
5 Adelie Torgersen 36.7 19.3 193 3450
6 Adelie Torgersen 39.3 20.6 190 3650
# ℹ 2 more variables: sex <fct>, year <int>
ggplot()
ggplot()
+ dataggplot()
+ data + aestheticsggplot()
+ data + aesthetics + geometryScatter plot
RColorBrewer
ggthemes
theme_bw()
theme_minimal()
labs()
ggplot(
data = penguins,
aes(x = bill_length_mm, y = bill_depth_mm, color = species)
) +
geom_point() +
scale_color_manual(values = c("#19a6b3","#f26c0d","#5e3894")) +
theme_minimal() +
labs(
title = "Bill dimensions of penguins",
subtitle = "Palmer penguins dataset",
caption = "Source: palmerpenguins package",
x = "Bill length, mm",
y = "Bill depth, mm",
color = "Species"
)
theme(legend.position = "top")
ggplot(
data = penguins,
aes(x = bill_length_mm, y = bill_depth_mm, color = species)
) +
geom_point() +
scale_color_manual(values = c("#19a6b3","#f26c0d","#5e3894")) +
theme_minimal() +
labs(
title = "Bill dimensions of penguins",
subtitle = "Palmer penguins dataset",
caption = "Source: palmerpenguins package",
x = "Bill length, mm",
y = "Bill depth, mm",
color = "Species"
) +
theme(legend.position = "top")
theme(legend.position = "none")
ggplot(
data = penguins,
aes(x = bill_length_mm, y = bill_depth_mm, color = species)
) +
geom_point() +
scale_color_manual(values = c("#19a6b3","#f26c0d","#5e3894")) +
theme_minimal() +
labs(
title = "Bill dimensions of penguins",
subtitle = "Palmer penguins dataset",
caption = "Source: palmerpenguins package",
x = "Bill length, mm",
y = "Bill depth, mm",
color = "Species"
) +
theme(legend.position = "none")
geom_smooth()
ggplot(data = penguins, aes(x = species, y = flipper_length_mm)) +
geom_boxplot(aes(color = species), width = 0.3, show.legend = FALSE) +
geom_jitter(aes(color = species), alpha = 0.5, show.legend = FALSE, position = position_jitter(width = 0.2, seed = 0)) +
scale_color_manual(values = c("darkorange", "purple", "cyan4")) +
labs(x = "Species",
y = "Flipper length (mm)") +
theme_minimal()
patchwork
library(patchwork)
p1 <- ggplot(
data = penguins,
aes(x = bill_length_mm, y = bill_depth_mm, color = species)
) +
geom_point() +
scale_color_manual(values = c("#19a6b3","#f26c0d","#5e3894")) +
theme_minimal()
p2 <- ggplot(
data = penguins,
aes(x = body_mass_g, fill = species)
) +
geom_density(alpha = 0.5) +
theme_minimal() +
facet_grid(~ species)
p3 <- ggplot(
data = penguins,
aes(x = species, y = body_mass_g, fill = species)
) +
geom_boxplot() +
theme_minimal()
(p1 | p2) / p3
ggstatsplot
GGally