Easily create segments in the y-axis of a 'ggplot2' plot.
This project builds on top of gg.gap v1.4 by Jiacheng Lou, et al.
What changed with respect to upstream?
You can install gggap
from CRAN:
install.packages("gggap")
A development version can be retrieved from Github:
# install.packages("devtools") devtools::install_github("cmoralesmx/gggap", ref="dev")
data(mtcars) library(ggplot2) p <- ggplot(data = mtcars, aes(x = gear, fill = gear)) + geom_bar() + ggtitle("Number of Cars by Gears") + xlab("Gears") # single segments and missing `tick_width` gggap(plot = p, segments = c(5, 10), ylim = c(0, 50)) # `tick_width` can be one or more numbers gggap( plot = p, segments = c(5, 10), tick_width = c(1, 10), ylim = c(0, 50) ) # segments list cantains more than one number vectors gggap( plot = p, segments = list(c(2.5, 4),c(5, 10)), tick_width = c(1, 0.5, 10), ylim = c(0, 50)) # `rel_heights` can set the relative height for segments and segmented y-axis gggap( plot = p, segments = list(c(2.5, 4),c(5, 10)), tick_width = c(1, 0.5, 10), rel_heights = c(0.2, 0, 0.2, 0,1), ylim = c(0, 50) ) # reversed y-axis p <- ggplot( data = mtcars, aes(x = gear, fill = gear) ) + geom_bar() + ggtitle("Number of Cars by Gears") + xlab("Gears")+ scale_y_continuous(trans = 'reverse') # single segments and missing tick_width gggap(plot = p, segments = c(10, 5), ylim = c(15, 0)) # for facet() library(ggplot2) p <- ggplot(mtcars, aes(mpg, hp)) + geom_point() p1 <- p + facet_wrap(~cyl, scales = "free") gggap(plot = p1, ylim = c(60, 200), segments = c(100, 120))
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4