Skip to content

Instantly share code, notes, and snippets.

@gireeshkbogu
Created January 22, 2016 14:43
Show Gist options
  • Save gireeshkbogu/bdb0e609ceb1c49da2ca to your computer and use it in GitHub Desktop.
Save gireeshkbogu/bdb0e609ceb1c49da2ca to your computer and use it in GitHub Desktop.
MYdata <- data.frame(Age = rep(c(0,1,3,6,9,12), each=20),
Richness = rnorm(120, 10000, 2500))
ggplot(data = MYdata, aes(x = Age, y = Richness)) +
geom_boxplot(aes(fill=factor(Age))) +
geom_point(aes(color = factor(Age))) +
scale_x_continuous(breaks = c(0, 1, 3, 6, 9, 12)) +
scale_colour_manual(breaks = c("0", "1", "3", "6", "9", "12"),
labels = c("0 month", "1 month", "3 months",
"6 months", "9 months", "12 months"),
values = c("#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#D55E00")) +
scale_fill_manual(breaks = c("0", "1", "3", "6", "9", "12"),
labels = c("0 month", "1 month", "3 months",
"6 months", "9 months", "12 months"),
values = c("#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#D55E00"))
ggplot(data = MYdata, aes(x = Age, y = Richness)) +
geom_boxplot(aes(colour=factor(Age)), fill=NA) +
geom_point(aes(color = factor(Age))) +
scale_x_continuous(breaks = c(0, 1, 3, 6, 9, 12)) +
scale_colour_manual(breaks = c("0", "1", "3", "6", "9", "12"),
labels = c("0 month", "1 month", "3 months",
"6 months", "9 months", "12 months"),
values = c("#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#D55E00"))
# link: http://stackoverflow.com/questions/10805643/ggplot2-add-color-to-boxplot-continuous-value-supplied-to-discrete-scale-er
@gireeshkbogu
Copy link
Author

box1
box2

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