Skip to content

Instantly share code, notes, and snippets.

@hadley
Created March 6, 2009 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadley/74686 to your computer and use it in GitHub Desktop.
Save hadley/74686 to your computer and use it in GitHub Desktop.
measure <- structure(list(age = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L,
4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c("7-yrs", "11-yrs",
"15-yrs", "21-yrs"), class = "factor"), trt = structure(c(2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L), .Label = c("alternation",
"repetition"), class = "factor"), value = c(814, 500, 424, 394,
967, 574, 472, 446, 10, 6, 6, 4, 13, 7, 6, 3), variable = c("rt",
"rt", "rt", "rt", "rt", "rt", "rt", "rt", "error", "error", "error",
"error", "error", "error", "error", "error")), .Names = c("age",
"trt", "value", "variable"), row.names = c(NA, 16L), class = "data.frame")
plot <- ggplot(measure, aes(age, value, colour = trt, fill = trt)) +
facet_grid(variable ~ . , scale = "free")
plot + geom_bar(position = "dodge")
plot + geom_line(aes(group = trt)) + geom_point()
# It's then just a matter of combining the two:
plot +
geom_bar(position = "dodge", subset = variable == "rt") +
geom_line(aes(group = trt), subset = variable == "error")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment