Skip to content

Instantly share code, notes, and snippets.

@ericpgreen
Last active September 12, 2018 14:53
Show Gist options
  • Select an option

  • Save ericpgreen/defe7e1c30ded366196a95ed7182c94a to your computer and use it in GitHub Desktop.

Select an option

Save ericpgreen/defe7e1c30ded366196a95ed7182c94a to your computer and use it in GitHub Desktop.
library(tidyverse)
library(ggrepel)
dat <- structure(list(quarter = 1:48,
year = c(2001L, 2001L, 2001L, 2001L, 2002L, 2002L, 2002L,
2002L, 2003L, 2003L, 2003L, 2003L, 2004L, 2004L,
2004L, 2004L, 2005L, 2005L, 2005L, 2005L, 2006L,
2006L, 2006L, 2006L, 2007L, 2007L, 2007L, 2007L,
2008L, 2008L, 2008L, 2008L, 2009L, 2009L, 2009L,
2009L, 2010L, 2010L, 2010L, 2010L, 2011L, 2011L,
2011L, 2011L, 2012L, 2012L, 2012L, 2012L),
value = c(15.05244755, 16.52097902, 17.15034965,
16.67832168, 14.79020979, 16.57342657,
15.20979021, 14.10839161, 16.73076923,
16.62587413, 18.46153846, 18.3041958,
17.41258741, 18.09440559, 18.40909091,
17.62237762, 17.77972028, 18.40909091,
19.51048951, 20.76923077, 19.24825175,
20.45454545, 19.66783217, 20.71678322,
19.56293706, 20.50699301, 21.34615385,
19.24825175, 21.29370629, 23.07692308,
24.02097902, 22.08041958, 23.4965035,
24.54545455, 24.49300699, 24.80769231,
24.54545455, 26.01398601, 26.11888112,
24.96503497, 26.53846154, 26.32867133,
26.22377622, 25.85664336, 26.8006993,
26.90559441, 27.27272727, 27.43006993),
study = structure(c(1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L),
.Label = c("", "Study 1", "Study 2"),
class = "factor"),
series = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L)),
class = "data.frame", row.names = c(NA, -48L))
dat %>%
ggplot(., aes(x = factor(quarter), y = value,
group = series)) +
geom_line(color="grey50") +
geom_point() +
scale_y_continuous(breaks=c(0, 5, 10, 15, 20, 25, 30),
limits=c(0, 30),
minor_breaks = NULL) +
scale_x_discrete(breaks = c(1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45),
labels=c("2001", "2002", "2003", "2004", "2005", "2006",
"2007", "2008", "2009", "2010", "2011", "2012")) +
geom_vline(xintercept=4, color = "grey", linetype = "dashed") +
geom_vline(xintercept=33, color = "grey", linetype = "dashed") +
# geom_label_repel(aes(label = study),
# size = 3.5,
# segment.color = "grey50",
# nudge_y = 27 - dat$value) +
annotate("text", x = 6, y = 29, label = "Study 1", color="grey50") +
annotate("text", x = 35, y = 29, label = "Study 2", color="grey50") +
theme_bw() +
theme(plot.background = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
axis.line.x = element_line(color = 'black'),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
axis.ticks.y = element_blank()) +
ggtitle("Percentage of I.C.U Admissions With Tight Glycemic Control")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment