gpt4 book ai didi

r - 如何删除 R 中直方图中的零标签?

转载 作者:行者123 更新时间:2023-12-05 01:17:53 25 4
gpt4 key购买 nike

有什么技巧可以去除直方图条之间的零标签吗?

enter image description here

hist(links$Survey_Duration, breaks = seq(0,50,5), main = "Survey Duration",
labels = TRUE, border = "black",
xlab = "Survey", ylim = c(0, 15), col = "gray", las = 1, xaxt='n')

axis(side=1, at=seq(0,50,5), labels=seq(0,50,5))

abline(v = mean(links$Survey_Duration), col = "royalblue", lwd = 1.5)

abline(v = median(links$Survey_Duration), col = "red", lwd = 1.5)

legend(x = "topright", c("Mean", "Median"), col = c("royalblue","red"),
lwd = c(1.5,1.5))

最佳答案

这个怎么样?

# modify data so there's zero in one of the bins
mtcars$mpg <- ifelse(mtcars$mpg >= 25 & mtcars$mpg <= 30, NA, mtcars$mpg)

# save plot parameters
h <- hist(mtcars$mpg, plot = FALSE)

# produce plot
plot(h, ylim = c(0, 14))

# add labels manually, recoding zeros to nothing
text(h$mids, h$counts + 1, ifelse(h$counts == 0, "", h$counts))

hist_no_zero

关于r - 如何删除 R 中直方图中的零标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48387862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com