在 R 中断开 X 轴 [英] Break X Axis in R

查看:59
本文介绍了在 R 中断开 X 轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的绘图中得到一个损坏的 X 轴.在 x 轴我喜欢插入一个断轴符号 <//> [从 2 开始到 8 结束,这意味着 2-8 将隐藏在 <//> 符号] 以便强调其他值.在 Matlab 中,此任务是通过使用 BreakXAxis 来执行的.在 R 中,plotrix 库有帮助只是插入一个中断轴符号,仅此而已.

I want to get a broken X-axis in my plot. In the x-axis I like to insert a broken-axis symbol < // > [starting from 2 and ended in end 8 which means 2-8 will be hidden in < // > symbol] so the other values can be emphasized. In Matlab, this task is performed by using BreakXAxis. In R, plotrix library helps only to plugin a break-axis symbol, that's all.

x <- c(9.45, 8.78, 0.93, 0.47, 0.24, 0.12)
y <- c(10.72, 10.56, 10.35, 10.10, 9.13, 6.72)
z <- c(7.578, 7.456, 6.956, 6.712, 4.832, 3.345)
plot(x, y, col='blue', pch=16, xlab= 'x', ylab='y, z')
points(x, z, col='red', pch=17)
library(plotrix)
axis.break(1,2,style="slash") 

推荐答案

xgap <- ifelse(x > 8, x-6, x)
#Possibly you'd want to check if there are values between 2 and 8.
plot(xgap, y, col='blue', pch=16, xlab= 'x', ylab='y, z', xaxt="n")
points(xgap, z, col='red', pch=17)
xat <- pretty(xgap)
xat <- xat[xat!=2]
xlab <- ifelse(xat>2, xat+6, xat)
axis(1,at=xat, labels=xlab)
library(plotrix)
axis.break(1,2,style="slash") 

不要这样做.gap.plot 提供了一个稍微好一点的替代方案,但我可能会使用 facets,例如,使用 ggplot2.

Don't do this. gap.plot provides a slightly better alternative, but I would probably use facets, e.g., with ggplot2.

这篇关于在 R 中断开 X 轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆