Skip to content

Instantly share code, notes, and snippets.

@farach
Last active May 18, 2021 10:52
Show Gist options
  • Save farach/bfa28d2143129e4e249d8c8a9be060de to your computer and use it in GitHub Desktop.
Save farach/bfa28d2143129e4e249d8c8a9be060de to your computer and use it in GitHub Desktop.
library(palmerpenguins)
library(tidyverse)
library(ggside)
library(magick)
library(grid)
logo_pp <- image_read("../pp_logo.png")
logo_ggside <- image_read("../ggside_logo.png")
p <- penguins %>%
filter_all(~ !is.na(.)) %>%
ggplot(aes(bill_depth_mm, bill_length_mm)) +
geom_point(aes(color = sex), alpha = 0.75) +
geom_xsidehistogram(
aes(y = after_stat(count), fill = sex),
alpha = 0.75,
size = 1,
position = "stack"
) +
geom_ysidehistogram(
aes(x = after_stat(count), fill = sex),
alpha = 0.75,
size = 1,
position = "stack"
) +
scale_color_viridis_d() +
scale_fill_viridis_d() +
theme_afs() + # can use theme_minimal()
theme(
legend.position = "bottom",
axis.title.y = element_text(margin = margin(t = 0, r = 10, b = 0, l = 0))
) +
labs(
y = "Bill length",
x = "Bill depth",
color = "Sex: ",
fill = NULL,
title = "Palmer Penguins Example Dataset",
subtitle = "This is an example of the ggside package",
caption = "Source:\nhttps://allisonhorst.github.io/palmerpenguins/\nhttps://github.com/jtlandis/ggside"
) +
guides(
fill = FALSE,
color = guide_legend(override.aes = list(size = 5, alpha = 1))
)
p
grid.raster(
logo_pp,
x = 0.02,
y = 0.01,
just = c("left", "bottom"),
width = unit(0.75, "inches")
)
grid.raster(
logo_ggside,
x = 0.12,
y = 0.01,
just = c("left", "bottom"),
width = unit(0.75, "inches")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment