在画图的时候,某些分组的value偏大,可视化的时候需要对y轴的数值进行截断处理。因为常使用ggplot2包作图,所以找到了gg.gap,它是专门针对ggplot2作图对象的R包。
安装R包
# CRAN包
install.packages("gg.gap")
# development version from github
# install.packages("devtools")
devtools::install_github("ChrisLou-bioinfo/gg.gap")
导入数据
library(ggplot2)
library(gg.gap)
data(mtcars)
原始图
p<-ggplot(data = mtcars, aes(x = gear, fill = gear)) +
geom_bar() +
ggtitle("Number of Cars by Gear") +
xlab("Gears")
p

设置tick_width参数调整阶段区域的y轴展示
- 不设置tick_width时,上下区域y轴显示间隔一致
gg.gap(plot=p,
segments=c(5,10),
ylim=c(0,50))

- 设置tick_width,分别显示各自区域的y轴
gg.gap(plot=p,
segments=c(5,10),
tick_width = c(1,10),
ylim=c(0,50))

- 设置不同的tick_width参数显示
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可以设置每个区域的高度
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))

参考
参考文章如引起任何侵权问题,可以与我联系,谢谢。
网友评论