r - 在 R 的直方图中正确标记 x 轴

标签 r histogram

我试着正确命名 x 轴。

hist(InsectSprays$count, col='pink', xlab='Sprays', labels=levels(InsectSprays$spray), xaxt='n')
axis(1, at=unique(InsectSprays$spray), labels=levels(InsectSprays$spray))

但这会产生

enter image description here

我想要栏下方而不是顶部的字母。

最佳答案

您必须在直方图 bin 中点处绘制标签。如果你想删除轴而只有字母,padj 会将字母移近你刚删除的轴。

h <- hist(InsectSprays$count, plot = FALSE)

plot(h, xaxt = "n", xlab = "Insect Sprays", ylab = "Counts",
     main = "", col = "pink")
axis(1, h$mids, labels = LETTERS[1:6], tick = FALSE, padj= -1.5)

enter image description here

关于r - 在 R 的直方图中正确标记 x 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38994579/

相关文章:

音频分割

c - 使用从 OpenCV 中的直方图生成的值来屏蔽图像数据

r - ggplot2:geom_ribbon,alpha 取决于每个 x 沿 y 轴的数据密度

list - 如何计算行数?

r - 如何为 R 更改 ggplot2 中 bin 的位置

matlab - Matlab中具有不同维度的多个数据集的直方图

r - 收到错误 "' xreg' 和 'newxreg' 有不同的列数”

r - 如何将 R 中的积分结果分配给数值变量?

r - 按因子水平选择行

python - python中的部分阴影直方图