在直方图中创建轴间隙

发布于 2025-01-25 09:18:58 字数 864 浏览 3 评论 0原文

我试图在0.6和1之间的直方图(在Y轴上)中创建差距,但真的不知道该如何解决。 gap.barplot解决方案似乎不起作用,我很乐意保持与其他景观一致的美感。理想情况下,它看起来像这样:

 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))

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"))

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. 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. Ideally it would look something like this: enter image description here

The general plot code attempt looks like this:

 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"))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久随 2025-02-01 09:18:58

将值设置为零。

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)


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

Set the value to zero.

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

enter image description here

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

enter image description here


Data:

set.seed(42)
h <- hist(runif(100, 0, 10), breaks = seq(0, 10, 0.5), plot = FALSE)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文