Created
March 25, 2014 17:27
-
-
Save saraemoore/9766858 to your computer and use it in GitHub Desktop.
ggplot geom_boxplot with box fill and correctly spaced x-axis scale
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
ggplot(data.df, aes(x=factor(time), y=value)) + | |
geom_boxplot(aes(fill=measure)) + | |
xlab("Time (time units)") + ylab("Value (value units)") + | |
scale_fill_discrete(name = "Measure") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ggplot(data.df, aes(x=time, y=value)) + | |
geom_boxplot(aes(fill=measure)) + | |
xlab("Time (time units)") + ylab("Value (value units)") + | |
scale_fill_discrete(name = "Measure") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ggplot(data.df, aes(x=time, y=value)) + | |
geom_boxplot(aes(fill=measure, group=factor(time))) + | |
xlab("Time (time units)") + ylab("Value (value units)") + | |
scale_fill_discrete(name = "Measure") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ggplot(data.df, aes(y=value, x=time)) + | |
geom_boxplot(aes(position = factor(time), fill=measure)) + | |
xlab("Time (time units)") + ylab("Value (value units)") + | |
scale_fill_discrete(name = "Measure") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ggplot(data.df, aes(y=value, x=time)) + | |
geom_boxplot(aes(position = factor(time), fill=measure)) + | |
scale_x_continuous(breaks = unique(data.df$time)) + | |
xlab("Time (time units)") + ylab("Value (value units)") + | |
scale_fill_discrete(name = "Measure") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data.df = data.frame(time = rep(c(0,3,6,12,24,48),each=50), | |
value = rnorm(300, 20, 5), | |
measure = factor(rep(rep(c("A","B"),each=25), 6))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment