Last active
January 19, 2023 11:58
-
-
Save BerriJ/edf1e9a9ac7cef2f455599dbd9acc737 to your computer and use it in GitHub Desktop.
Snippets for plotting with 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(dplyr) | |
library(ggplot2) | |
library(ggsci) | |
library(tidyr) | |
material_pals <- c( | |
"red", "pink", "purple", "deep-purple", "indigo", | |
"blue", "light-blue", "cyan", "teal", "green", "light-green", "lime", | |
"yellow", "amber", "orange", "deep-orange", "brown", "grey", "blue-grey" | |
) | |
cols <- purrr::map(material_pals, ~ pal_material(.x)(10)) %>% | |
purrr::reduce(cbind) | |
colnames(cols) <- material_pals | |
cols %>% | |
as_tibble() %>% | |
mutate(idx = as.factor(1:10)) %>% | |
pivot_longer(-idx, names_to = "var", values_to = "val") %>% | |
mutate(var = factor(var, levels = material_pals[19:1])) %>% | |
ggplot() + | |
xlab(NULL) + | |
ylab(NULL) + | |
geom_tile(aes(x = idx, y = var, fill = val)) + | |
scale_fill_identity() + | |
scale_x_discrete(expand = c(0, 0)) + | |
scale_y_discrete(expand = c(0, 0)) + | |
theme_minimal() -> plot_cols |
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
# Tell tikzdevice which documentclass you are using so that element dims are calculated accordingly. | |
options(tikzDocumentDeclaration = "\\documentclass[preprint,12pt]{elsarticle}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment