ggplot阶截断坐标轴-gggap

目录

gggap包安装

功能查询

简单版使用代码

 复杂版使用代码


gggap包安装

CRAN: Package gggap (-project.org)

手动下载安装


功能查询
> ?gggap
> ?gggap

Define Segments in y-Axis for 'ggplot2'

Description

Easy-to-define segments in y-axis for 'ggplot2'.

Usage

gggap(plot, ylim, segments, tick_width, rel_heights, vjust = 0,
  margin = c(top = 1, right = 2, bottom = 1, left = 1), ...)

Arguments

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'.


简单版使用代码
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)
)

 复杂版使用代码
gggap(
  plot = p,
  segments = list(c(2.5, 4), c(5, 10)),  #设置两个阶段 c(2.5, 4), c(5, 10)
  tick_width = c(1, 0.5, 10),            #设置不同部分的坐标间隔
  rel_heights = c(0.2, 0, 0.2, 0, 1),    #相对分段y轴和分段高度的数值向量,默认值为1和0
  ylim = c(0, 50)
)

箱线图汇总ggplot2(自备)_ggplot2箱线图-CSDN博客

gg.gap:ggplot阶截断坐标轴的优秀完美解决方案-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值