Skip to content

Instantly share code, notes, and snippets.

@elsherbini
Created May 9, 2018 14:04
Show Gist options
  • Save elsherbini/a6eddbf1472f381c39204d43579efb73 to your computer and use it in GitHub Desktop.
Save elsherbini/a6eddbf1472f381c39204d43579efb73 to your computer and use it in GitHub Desktop.
Trying to get nice labels
library(tidyverse)
library(cowplot)
dummy_data <- tibble(combo_id = seq_len(8), factor1=rep(c("1a","1b"), times=4), factor2=rep(rep(c("2a","2b"), each=2), times=2), factor3=rep(c("3a","3b"),each=4)) %>%
{replicate(8, ., simplify = FALSE)} %>%
bind_rows() %>%
group_by(combo_id) %>%
mutate(value=rpois(8, 2*combo_id))
head(dummy_data)
p1 <- dummy_data %>%
ggplot(aes(x=combo_id, y=value)) +
geom_jitter(aes(alpha=factor1, color=factor2, shape=factor3), size=3, width = 0.25) +
stat_summary(fun.y = mean, fun.ymin = mean, fun.ymax = mean,
geom = "crossbar", width = 0.25) +
theme(plot.margin = unit(c(0, 0, 4, 0), "lines"),
axis.title.x = element_blank(),
axis.text.x = element_text(angle = 90, hjust = 1),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank())+
scale_alpha_discrete(range=c(0.5,0.9))
ggdraw(p1) +
draw_plot_label(rep(unique(dummy_data$factor1), 4), seq_len(8)/16, rep(c(.07), 8)) +
draw_plot_label(rep(unique(dummy_data$factor2), 2), seq_len(4)/8, rep(c(.12), 4)) +
draw_plot_label(unique(dummy_data$factor3), seq_len(2)/4, rep(c(.17), 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment