Skip to content

Instantly share code, notes, and snippets.

@gireeshkbogu
Last active January 22, 2016 10:53
Show Gist options
  • Save gireeshkbogu/b0d531e421665ca190c3 to your computer and use it in GitHub Desktop.
Save gireeshkbogu/b0d531e421665ca190c3 to your computer and use it in GitHub Desktop.
> meanstable
x_categories strata mu lo hi
1 Facet A Strata 1 0.020 -0.001 0.04
2 Facet A Strata 2 0.004 -0.010 0.03
3 Facet A Strata 3 0.070 0.030 0.16
4 Facet A Strata 4 0.120 0.070 0.23
5 Facet B Strata 1 -0.020 -0.030 0.01
6 Facet B Strata 2 0.040 0.020 0.07
7 Facet B Strata 3 0.040 -0.060 0.09
8 Facet B Strata 4 0.110 -0.010 0.20
anodf2 <-
structure(
list(
x = c(1.5, 2.5),
y = c(0.085, 0.215),
x_categories = structure(c(1L, 1L),
class = "factor",
.Label = "Facet B")),
.Names = c("x", "y", "x_categories"),
row.names = c(NA, -2L),
class = "data.frame")
ggplot(meanstable) +
geom_hline(yintercept=0, linetype="dashed", colour="grey55") +
geom_pointrange(size = 1.2,
aes(x = strata, ymin = lo, ymax = hi, y = mu,
color = x_categories)) +
facet_wrap(~x_categories, nrow = 1) +
scale_colour_manual(values = c("Facet A" = "blue", "Facet B" = "red")) +
scale_x_discrete("X Axis Label") +
scale_y_continuous("Y Axis Label") +
theme(legend.position = "none",
strip.text.x = element_text(size = rel(1.5)),
axis.title.y = element_text(vjust=1.4, size = rel(1.4)),
axis.title.x = element_text(vjust=-0.2, size = rel(1.4)),
axis.text = element_text(size = rel(1.1)),
plot.margin = unit(c(1, 1, 1, 1), "cm")) +
geom_segment(data = segdf, size = .8,
aes(x=x, y=y, xend=xend, yend=yend, x_categories = x_categories)) +
geom_text(data = anodf, aes(x=x, y=y, x_categories = x_categories),
label=c("*", "**", "*"), size = 8) +
geom_segment(data = segdf2, size = .8,
aes(x=x, y=y, xend=xend, yend=yend, x_categories = x_categories)) +
geom_text(data = anodf2, aes(x=x, y=y, x_categories = x_categories),
label=c("***", "**"), size = 8)
helpful links: http://stackoverflow.com/questions/29220271/different-colored-values-by-facet-in-ggplot2-geom-pointrange-with-significance-a
@gireeshkbogu
Copy link
Author

4437c2a0-c0f6-11e5-9e05-4580d9082ed0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment