Created
September 9, 2016 11:55
-
-
Save jergosh/3308cd43b2a18451a3483f1711c67588 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
library(ggplot2) | |
library(grid) | |
library(gtable) | |
ex <- data.frame(xmin=1, xmax=100, ymin=0, ymax=15) | |
p <- ggplot(ex, aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax)) + | |
theme_minimal() + | |
theme(plot.margin=margin(l=2.0, unit="cm"), | |
panel.margin=margin(l=2.0, r=0, unit="cm"), | |
panel.grid.major.x=element_blank(), panel.grid.minor.x=element_blank(), | |
panel.border=element_blank(), panel.background = element_blank(), | |
axis.text.y=element_text(margin=margin(l=0.0, r=0.0, unit="cm")), | |
axis.ticks=element_line(size=0.25), | |
axis.ticks.x=element_line(), axis.ticks.y=element_line(), | |
axis.ticks.length=unit(0.1, units="cm")) + | |
scale_x_continuous(expand = c(0, 0)) + | |
scale_y_continuous(expand = c(0, 0)) + | |
geom_rect() | |
ex_ann <- data.frame(xmin=10, xmax=50, ymin=0, ymax=1) | |
ann <- ggplot(ex_ann, aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax)) + | |
theme_minimal() + | |
theme(plot.margin=margin(l=2.0, unit="cm"), | |
panel.margin=margin(l=2.0, unit="cm"), | |
panel.background=element_rect(fill="grey", colour="white"), | |
panel.grid.major.x=element_blank(), panel.grid.minor.x=element_blank(), | |
panel.grid.major.y=element_blank(), panel.grid.minor.y=element_blank(), | |
panel.border=element_blank(), panel.background=element_blank(), | |
# axis.text.y=element_text(margin=margin(r=0, l=0.5)), panel.margin=unit(0, units="cm"), | |
axis.ticks=element_line(size = 0.25), | |
axis.ticks.x=element_line(), axis.ticks.y=element_blank(), | |
axis.text.y=element_blank(), | |
axis.ticks.length=unit(0.0, units="cm")) + | |
scale_x_continuous(limits=c(1, 100), expand = c(0, 0)) + | |
scale_y_continuous(limits=c(0, 1), expand = c(0, 0)) + | |
geom_rect() | |
gr <- ggplotGrob(p) | |
gr_ann <- ggplotGrob(ann) | |
g <- gtable(widths=unit(c(1), "null"), heights=unit(c(1, 0.1), "null")) | |
g <- gtable_add_grob(g, list(gr, gr_ann), t=c(1, 2), l=c(1, 1), r=c(1, 1), b=c(1, 2)) | |
grid.newpage() | |
grid.draw(g) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment