我发现了很多解决轴中断和间隙的问题和答案。但大多数都是低质量的(SO 意义上的),因为没有示例代码、没有图片或复杂的代码。这就是我问的原因。
我尝试使用library(plotrix)
。如果有一个没有它和/或另一个库的解决方案,那对我来说也可以。
这是正常的 R 条形图。
barplot(c(10,20,500))
为了打破轴并增加间隙,我尝试了这个。
gap.barplot(c(10,20,500),gap=c(50,400), col=FALSE)
结果是不漂亮.
- 条之间没有空间。
space
参数来自barplot()
不被接受gap.barplot()
.
- 这些条具有不同的宽度。
- 抽动的位置不在条形的中间。
我可以用以下方式控制该参数吗plotrix
?我在文档中没有看到有关它的内容。
有其他库或解决方案可以解决我的问题吗?
由于个人问题很多,所以有很多不同的答案。针对您的问题,您可以尝试以下方法。但总有更好的解决方案。在我看来,显示完整的数据总是比裁剪数据更好。
# Your data with names
library(plotrix)
d <- c(10,20,500)
names(d) <- letters[1:3]
# Specify a cutoff where the y.axis should be splitted.
co <- 200
# Now cut off this area in your data.
d[d > co] <- d[d > co] - co
# Create new axis label using the pretty() function
newy <- pretty(d)
newy[ newy > co] <- newy[ newy > co] + co
# remove values in your cutoff.
gr <- which(newy != co)
newy <- newy[ gr ]
# plot the data
barplot(d, axes=F)
# add the axis
axis(2, at = pretty(d)[gr], labels = newy)
axis.break(2, co, style = "gap")
As an alternative you can try to log your axis using log="y"
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)