Skip to content

Instantly share code, notes, and snippets.

@AlbertRapp
Created June 7, 2022 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlbertRapp/d775d967b0f9c0a247c55c362975eece to your computer and use it in GitHub Desktop.
Save AlbertRapp/d775d967b0f9c0a247c55c362975eece to your computer and use it in GitHub Desktop.
polar_coord_legend.R
camcorder::gg_record(
dir = 'img',
height = 16,
width = 16,
units = 'cm'
)
library(tidyverse)
library(ggforce)
dat <- tibble(
xmin = seq(35, 75, 5),
xmax = seq(40, 80, 5),
ymin = 8.5,
ymax = 10
)
dat_circle <- tibble(xmin = 15, xmax = 100, ymin = -5, ymax = 12)
dat %>%
ggplot() +
geom_rect(data = dat_circle, aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax), fill = 'white') +
geom_rect(aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax, fill = xmin), col = 'white') +
geom_text(data = slice(dat, 1:8), aes(x = xmax, y = ymax + 1, label = xmax), vjust = c(rep(0, 3), rep(0.5, 2), rep(1, 3))) +
scale_fill_gradient(
low = '#faebe3',
high = '#6d1f73'
) +
coord_polar(start = pi) +
scale_x_continuous(limits = c(15, 100), breaks = seq(40, 75, 5), labels = seq(40, 75, 5)) +
scale_y_continuous(limits = c(-5, 15)) +
theme_void() +
theme(
legend.position = 'none',
plot.background = element_rect(fill = 'grey80')
) +
annotate(
'text',
x = 57.5,
y = 3,
label = '50 dB',
size = 16,
) +
annotate(
'text',
x = 57.5,
y = -5,
label = 'Noise Intensity (dB)',
size = 8,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment