Created
January 21, 2015 15:40
-
-
Save hrbrmstr/3c75c362bba153290315 to your computer and use it in GitHub Desktop.
IV MOOC Assignment 2 (temporal) ggplot code
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) | |
library(dplyr) | |
library(gridExtra) | |
dat <- read.csv("data/burst.csv") # generated by Sci2 | |
dat$idx <- rownames(dat) | |
dat$size <- dat$Weight / dat$Length | |
gg <- ggplot(dat, aes(x=Start, xend=End, y=reorder(idx, Start), yend=idx)) | |
gg <- gg + geom_vline(data=data.frame(x=seq(1932, 2007, 5)), | |
aes(xintercept=x), | |
linetype="dashed", color="#7f7f7f", size=0.5, alpha=0.5) | |
gg <- gg + geom_segment(aes(size=size), color="#6a3d9a") | |
gg <- gg + geom_text(aes(x=Start-0.5, y=idx, label=Word), | |
hjust=1, size=4) | |
gg <- gg + scale_x_continuous(breaks=seq(1932, 2007, 5), | |
limits=c(1930, 2007)) | |
gg <- gg + scale_size_continuous(name="Fewer #\nof Publications", | |
range=c(1, 18), | |
labels=c("", "", "", "", "Larger #\nof Publications")) | |
gg <- gg + labs(x=NULL, y=NULL, | |
title="MEDLINE Mesothelioma Research\n(1932-2007)\n") | |
gg <- gg + theme_bw() | |
gg <- gg + theme(axis.text.x=element_text(size=15, vjust=7)) | |
gg <- gg + theme(panel.border=element_blank()) | |
gg <- gg + theme(panel.grid=element_blank()) | |
gg <- gg + theme(legend.position=c(0.1, 0.7)) | |
gg <- gg + theme(axis.ticks.y=element_blank()) | |
gg <- gg + theme(axis.ticks.x=element_blank()) | |
gg <- gg + theme(axis.text.y=element_text(color="white")) | |
gg <- gg + theme(plot.title=element_text(size=28, hjust=0, face="bold")) | |
timeline <- gg | |
# generated by the database export | |
pubs <- read.csv("data/sdb/mesothelioma-1000-from-MEDLINE_master_table.csv", | |
stringsAs=FALSE, header=TRUE) | |
pubs %>% | |
count(published_year) -> pub_count | |
gg <- ggplot(pub_count, aes(x=published_year, y=n)) | |
gg <- gg + geom_vline(data=data.frame(x=seq(1932,2007,5)), | |
aes(xintercept=x), | |
linetype="dashed", color="#7f7f7f", size=0.5, alpha=0.5) | |
gg <- gg + geom_bar(stat="identity", fill="#6a3d9a", color="white") | |
gg <- gg + scale_x_continuous(breaks=seq(1932, 2007, 5), limits=c(1930, 2007)) | |
gg <- gg + labs(x=NULL, y=NULL, title=NULL) | |
gg <- gg + theme_bw() | |
gg <- gg + theme(panel.border=element_blank()) | |
gg <- gg + theme(legend.position="none") | |
gg <- gg + theme(axis.ticks.y=element_blank()) | |
gg <- gg + theme(panel.grid.major.x=element_blank()) | |
gg <- gg + theme(panel.grid.minor.x=element_blank()) | |
gg <- gg + theme(axis.ticks.x=element_blank()) | |
gg <- gg + theme(axis.text.x=element_blank()) | |
gg <- gg + theme(panel.grid.major.y=element_line(linetype="dashed", color="#7f7f7f", | |
alpha=0.5, size=0.5)) | |
pub_bars <- gg | |
grid.arrange(timeline, pub_bars, ncol=1, heights=c(3,1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment