Description Usage Arguments Value Examples
Easy to define segments in y-axis for 'ggplot2'.
1 2 |
plot |
A 'ggplot2' plot. |
ylim |
The y-axis limits. |
segments |
The interval of a segment. If more than one intervals are given, please use list() to concatenate them. |
tick_width |
One or more numbers for each segmented y-axis. |
rel_heights |
Numerical vector of relative segmented y-axis and segments heights, default is 1 and 0. |
vjust |
Vertical justification. Default = 0 (baseline at y). |
margin |
Margins around the text. |
... |
Arguments will be handed to plot_grid() in 'cowplot'. |
A segmented picture.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | data(mtcars)
library(ggplot2)
p<-ggplot(data = mtcars, aes(x = gear, fill = gear)) +
geom_bar() +
ggtitle("Number of Cars by Gear") +
xlab("Gears")
#single segments and missing tick_width
gg.gap(plot=p,
segments=c(5,10),
ylim=c(0,50))
#tick_width can be one or more numbers
gg.gap(plot=p,
segments=c(5,10),
tick_width = c(1,10),
ylim=c(0,50))
#segments list cantains more than one number vectors
gg.gap(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
gg.gap(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 Gear") +
xlab("Gears")+
scale_y_continuous(trans = 'reverse')
#single segments and missing tick_width
gg.gap(plot=p,
segments=c(10,5),
ylim=c(15,0))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.