Skip to content

Instantly share code, notes, and snippets.

@clauswilke
Last active June 24, 2018 17:21
Show Gist options
  • Save clauswilke/53643ebcae934a10b91a9b6909ee0c27 to your computer and use it in GitHub Desktop.
Save clauswilke/53643ebcae934a10b91a9b6909ee0c27 to your computer and use it in GitHub Desktop.
Cheese plot of height and bodyfat % of Australian athletes
# original version
library(DAAG)
library(ggplot2)
library(ggridges)
ggplot(ais, aes(x=ht, y=sport, point_size=pcBfat, point_color=sex, group=sport)) +
geom_density_ridges(jittered_points=TRUE, scale = .8, rel_min_height = .01, fill = "gray90",
points_scaling_range = c(.1, .8)) +
scale_y_discrete(expand = c(.01, 0)) +
scale_x_continuous(expand = c(0, 0), name = "height [cm]") +
scale_point_size_continuous(range = c(0.1, 5), name = "% bodyfat") +
scale_discrete_manual("point_color", values = c("#D55E00", "#0072B2"), labels = c("female", "male")) +
guides(point_size = guide_legend(override.aes = list(fill = NA, color = NA)),
point_color = guide_legend(override.aes = list(fill = NA, color = NA, point_size = 4))) +
theme_ridges(center = TRUE)
# improved version with renamed y labels and separate distributions for men and women
library(DAAG)
library(ggplot2)
library(ggridges)
ais$sport <- factor(ais$sport,
levels = c("B_Ball", "Field", "Gym", "Netball", "Row", "Swim", "T_400m", "T_Sprnt", "Tennis", "W_Polo"),
labels = c("Basketball", "Field", "Gym", "Netball", "Row", "Swim", "Track 400m", "Track Sprint", "Tennis", "Water Polo"))
ggplot(ais, aes(x=ht, y=sport, point_size=pcBfat, point_color=sex, fill=sex)) +
geom_density_ridges(jittered_points=TRUE, scale = .8, rel_min_height = .01,
points_scaling_range = c(.1, .8)) +
scale_y_discrete(expand = c(.01, 0)) +
scale_x_continuous(expand = c(0, 0), name = "height [cm]") +
scale_point_size_continuous(range = c(0.1, 5), name = "% bodyfat") +
scale_fill_manual(values = c("#D55E0020", "#0072B220"), guide = "none") +
scale_discrete_manual("point_color", values = c("#D55E00", "#0072B2"), labels = c("female", "male")) +
guides(point_size = guide_legend(override.aes = list(fill = NA, color = NA)),
point_color = guide_legend(override.aes = list(fill = c("#D55E0020", "#0072B220"), color = NA, point_size = 4))) +
ggtitle("Height and % bodyfat in Australian athletes") +
theme_ridges(center = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment