Page last updated: 04 May, 2019
Examples
Density plot
##### Density plot
ggplot(data = movies,
aes(x = rating)) +
ylab("Density of Movie Rating") +
xlab("Score (out of 10)") +
geom_density(color = discrete_wes_pal[1],
fill = discrete_wes_pal[1],
alpha = 1) +
my_theme()
Density plot - facet_wrap()
##### Density plot - with multiple plots for each group
ggplot(data = movies,
aes(x = length, fill = Genre, color = Genre)) +
geom_density(alpha = 1) +
xlim(0,300) +
facet_wrap(~ Genre, ncol = 4) +
ylab("Density of length of film)") +
xlab("Length of film (minutes)") +
scale_fill_manual(values = discrete_wes_pal) +
scale_color_manual(values = discrete_wes_pal) +
guides(fill = guide_legend(override.aes = list(size = 5),
title = "",
label.hjust = 0,
label.vjust = 0.5),
color = FALSE) +
my_theme() +
theme(
strip.text.x = element_blank()
)
LS0tCnRpdGxlOiAiRGVuc2l0eSBwbG90cyIKb3V0cHV0OgogIGh0bWxfZG9jdW1lbnQ6CiAgICB0b2M6IGZhbHNlCiAgICBudW1iZXJfc2VjdGlvbnM6IGZhbHNlCiAgICBkZl9wcmludDogcGFnZWQKICAgIGNvZGVfZG93bmxvYWQ6IHRydWUKICAgIGhpZ2hsaWdodGVyOiBudWxsCi0tLQoKYGBge3Igc2V0dXAsIGV2YWw9VFJVRSwgaW5jbHVkZT1GQUxTRSwgZWNobz1GQUxTRSwgZXJyb3I9RkFMU0UsIG1lc3NhZ2U9RkFMU0UsIHdhcm5pbmc9RkFMU0UsIGNhY2hlPVRSVUUsIGZpZy5hbGlnbj0nY2VudGVyJywgY29tbWVudD0iIn0KY2hvb3NlQ1JBTm1pcnJvcihncmFwaGljcz1GQUxTRSwgaW5kPTEzMykKc291cmNlKCJzb3VyY2UvcGxvdHMtb3ZlcnZpZXcuUiIpCmBgYApfX18KClBhZ2UgbGFzdCB1cGRhdGVkOiBgciBmb3JtYXQoU3lzLnRpbWUoKSwgJyVkICVCLCAlWScpYAoKXCAgCgojIEV4YW1wbGVzIHsjZGVuc2l0eV9wbG90cyAudGFic2V0fQo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