Created
May 26, 2022 10:06
-
-
Save charliejhadley/0e3abbf237a2f8c4f7ff9b322677dcc9 to your computer and use it in GitHub Desktop.
facet-grid_space-free.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(hrbrthemes) | |
#> NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes. | |
#> Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and | |
#> if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow | |
# rebuilding https://blog.albertkuo.me/post/point-shape-options-in-ggplot/#fnref1 | |
pch_tib <- tibble( | |
pch_number = 0:25, | |
pch_description = c(rep("Outline", 15), | |
rep("Fill", 6), | |
rep("Both", 5)) | |
) %>% | |
mutate(pch_description = as_factor(pch_description), | |
pch_description = fct_relevel(pch_description, c("Outline", | |
"Fill", | |
"Both"))) | |
pch_outline <- pch_tib %>% | |
filter(pch_description == "Outline") %>% | |
mutate(x = rep(1:5, 3), | |
y = rev(sort(rep(c("a", "b", "c"), 5)))) | |
pch_fill <- pch_tib %>% | |
filter(pch_description == "Fill") %>% | |
mutate(x = 1:6, | |
y = rep("d", 6)) | |
pch_both <- pch_tib %>% | |
filter(pch_description == "Both") %>% | |
mutate(x = 1:5, | |
y = rep("e", 5)) | |
pch_outline %>% | |
bind_rows(pch_fill, pch_both) %>% | |
ggplot(aes(x = x, | |
y = y, | |
pch = pch_number)) + | |
geom_point(fill = "lightskyblue3", | |
color = "black", | |
size = 5) + | |
geom_text(aes(label = pch_number), | |
nudge_y = 0.4) + | |
facet_grid(pch_description ~ ., | |
scales = "free_y", switch = "y", | |
space = "free" | |
) + | |
scale_shape_identity() + | |
labs(title = 'Using facet_grid(space = "free")') + | |
theme_ipsum() + | |
theme(strip.text.y.left = element_text(angle = 0), | |
panel.grid.major = element_blank(), | |
panel.grid.minor = element_blank(), | |
axis.text.y = element_blank(), | |
axis.text.x = element_blank(), | |
axis.title.x = element_blank(), | |
axis.title.y = element_blank()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment