简体   繁体   English

在直方图中创建轴间隙

[英]Creating axis gap in histograms

I'm trying to create a gap in a histogram between 0.6 and 1 (on the y axis) but don't really know how to go about this.我试图在 0.6 和 1(在 y 轴上)之间的直方图中创建一个间隙,但我真的不知道如何解决这个问题 go。 The gap.barplot solution does not seem to work and i'd love to keep the aesthetic of the plots consistent with the other ones. gap.barplot 解决方案似乎不起作用,我希望保持绘图的美感与其他绘图一致。 Ideally it would look something like this:理想情况下,它看起来像这样: 在此处输入图像描述

The general plot code attempt looks like this:一般的 plot 代码尝试如下所示:

 h <- hist(benthosBx$length_mm, breaks = seq(0, 10, 0.5),  plot = FALSE)
h$counts <- h$counts / nrow(benthosBx)
gap.plot(h, xlab = 'Body length (mm)', ylab = '', gap = c(0.4,0.8),ylim = c(0,0.6), xlim = c(0,10), main = ' ', xaxt='n', yaxt='n', col = "grey")
axis(side=1, at=seq(0,10, 1))
axis(side=2, at=seq(0,1, 0.1))

dput of the data:数据输入:

structure(list(lakeID = c("WE2", "WE2"), length_mm = c(1.52172197930582, 
1.63884515191493), date = structure(c(1592352000, 1597881600), tzone = "UTC", class = c("POSIXct", 
"POSIXt")), year = c(2020L, 2020L)), row.names = c(NA, -2L), class = c("tbl_df", 
"tbl", "data.frame"))

Set the value to zero.将值设置为零。

plot(h, ylim = c(0,0.6), xlim = c(0,10), col = 8)

在此处输入图像描述

h$counts[h$breaks == 1] <- 0  ## set to zero
plot(h, ylim = c(0,0.6), xlim = c(0,10), col = 8)

在此处输入图像描述


Data:数据:

set.seed(42)
h <- hist(runif(100, 0, 10), breaks = seq(0, 10, 0.5), plot = FALSE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM