Skip to content

Instantly share code, notes, and snippets.

@farach
Created May 26, 2021 23:49
Show Gist options
  • Save farach/f1df3d6d3122ae926fa6a0f7d90c24b8 to your computer and use it in GitHub Desktop.
Save farach/f1df3d6d3122ae926fa6a0f7d90c24b8 to your computer and use it in GitHub Desktop.
library(palmerpenguins)
library(tidyverse)
library(magick)
library(grid)
library(gghalves)
logo_pp <- image_read("../pp_logo.png")
logo_gg <- image_read("../gghalves.png")
p <-
penguins %>%
filter_all(~ !is.na(.)) %>%
ggplot(aes(x = bill_length_mm, y = bill_depth_mm, fill = species)) +
geom_half_point(aes(color = species), alpha = 0.75, side = "l") +
geom_half_violin(alpha = 0.5, side = "r") +
facet_wrap(~ species) +
scale_x_continuous(breaks = seq(30, 60, 5)) +
scale_y_continuous(breaks = seq(15, 21, 2)) +
coord_flip() +
theme_afs() + # can use theme_minimal()
theme(
legend.position = "none",
plot.title = element_text(hjust = 0.5, lineheight = 1.1,
margin = margin(t = 0, r = 10, b = 0, l = 0)),
plot.caption = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
axis.title.x = element_text(hjust = 1, margin = margin(t = 20, r = 0, b = 10, l = 0)),
axis.title.y = element_text(hjust = 1, margin = margin(t = 0, r = 20, b = 0, l = 0)),
panel.spacing = unit(1, "lines"),
strip.background = element_blank()
) +
labs(
x = "Bill length (mm)",
y = "Bill depth (mm)",
title = "Palmer Penguins Example Dataset",
subtitle = "This is an example of the gghalves package",
caption = "Source:\nhttps://allisonhorst.github.io/palmerpenguins/\nhttps://github.com/erocoar/gghalves"
)
p
grid.raster(
logo_pp,
x = 0.05,
y = 0.1,
just = c("left", "bottom"),
width = unit(0.75, "inches")
)
grid.raster(
logo_gg,
x = 0.17,
y = 0.15,
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