Last active
January 2, 2016 21:39
-
-
Save dantalus/8364621 to your computer and use it in GitHub Desktop.
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
require(plyr) | |
require(ggplot2) | |
require(RColorBrewer) | |
Df <- data.frame(Method = replicate(100,sample(c("A","B","C", "D", "E"),1)), | |
Year = sample(c(1980:2014), 100, replace = T)) | |
Df$count <- 1 | |
Df <- Df[order(Df[,2]), ] # Sort by year | |
Df <- ddply(Df, .(Method), transform, cumsumMethod = cumsum(count)) | |
Df <- ddply(Df, .(Method), transform, MaxCount = max(cumsumMethod)) | |
Df$total <- cumsum(Df$count) | |
ggplot(Df, aes(x = Year, y = cumsumMethod, colour = Method, group = Method)) + | |
geom_line() | |
ggplot(Df,aes(x = Year,color = Method)) + | |
geom_step(aes(y = cumsumMethod)) | |
ggplot(Df,aes(x = Year,color = Method)) + | |
stat_bin(aes(y = cumsum(..count..)),geom="step") | |
brewer.pal(name = "Set1", n = 5) | |
scale <- c("A" = "#E41A1C", "B" = "#377EB8" , "C" = "#4DAF4A", | |
"D" = "#984EA3", "E" = "#FF7F00") | |
ggplot(Df,aes(x = Year, color = Method)) + | |
stat_bin(data = subset(Df, Method == "A"), | |
aes(y = cumsum(..count..)), | |
geom = "step", size = 3, alpha = .3) + | |
stat_bin(data = subset(Df, Method == "B"), | |
aes(y = cumsum(..count..)), | |
geom = "step", size = 3, alpha = .3) + | |
stat_bin(data = subset(Df, Method == "C"), | |
aes(y = cumsum(..count..)), | |
geom = "step", size = 3, alpha = .3) + | |
stat_bin(data = subset(Df, Method == "D"), | |
aes(y = cumsum(..count..)), | |
geom = "step", size = 3, alpha = .3) + | |
stat_bin(data = subset(Df, Method == "E"), | |
aes(y = cumsum(..count..)), | |
geom = "step", size = 3, alpha = .3) + | |
stat_bin(data = subset(Df, Method == "A"), | |
aes(y = cumsum(..count..)), | |
geom = "step", size = 1) + | |
stat_bin(data = subset(Df, Method == "B"), | |
aes(y = cumsum(..count..)), | |
geom = "step", size = 1) + | |
stat_bin(data = subset(Df, Method == "C"), | |
aes(y = cumsum(..count..)), | |
geom = "step", size = 1) + | |
stat_bin(data = subset(Df, Method == "D"), | |
aes(y = cumsum(..count..)), | |
geom = "step", size = 1) + | |
stat_bin(data = subset(Df, Method == "E"), | |
aes(y = cumsum(..count..)), | |
geom = "step", size = 1) + | |
# stat_bin(aes(y = cumsum(..count..)),geom = "step", size = 2) + | |
coord_cartesian(xlim = c(1980, 2014)) + | |
ylab("Cummulative Count of Publications") + | |
xlab("Year of Publication") + | |
ggtitle("Figure X. Cummulative count of infant body composition\npublications, by method of measurement used (1990 - 2014)") + | |
theme(plot.background = element_rect(fill = "white"), | |
strip.background = element_rect(fill = "white"), | |
text = element_text(color = "black", family = "mono"), | |
axis.text.x = element_text(color = "black"), | |
axis.text.y = element_text(color = "black"), | |
plot.title = element_text(hjust = 0)) + | |
scale_color_brewer(name = "Method of Measurement", palette = "Set1", | |
breaks = c("E", "D", "A", "B", "C")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment