gpt4 book ai didi

r - ggplot 中的直方图在 X 轴上不是从零开始

转载 作者:行者123 更新时间:2023-12-04 17:43:01 29 4
gpt4 key购买 nike

<分区>

所以,这是第一次使用 ggplot 制作直方图,我看到的是,对于我的数据,导出的直方图如下所示。

enter image description here

我不喜欢的是,第一个 bin 不包含零,它从大约 5 或 6 开始。有人遇到过这样的事情吗?

我使用了一系列 binwidths,从 1 到 20,它一直在这样做。

数据:

structure(list(V1 = c(8, 4.4, 9.4, 29.4, 135.6, 65, 70.9, 15.2, 38.8, 87.2, 5.2, 0.2, 7.8, 46.4, 35.9, 77.4, 34.2, 157.4, 46.4, 19, 43.8, 41.2, 96.8, 25.6, 40.2, 111.8, 111.8, 49.8, 39.4, 9.6, 11.6, 8.6, 44.2, 41, 4.6, 36.2, 12.4, 45.8, 0, 30.8, 134.6, 167.2, 13.8, 56.6, 112.3, 13.6, 18.8, 18.2, 7, 40.4, 30.8, 130.2, 234.6, 106.2, 87.2, 15, 7.6, 63, 18, 2.6, 28, 24, 153.2, 24.4, 69.6, 27, 134, 181.6, 46, 85.4, 18.6, 32, 83.6, 42.6, 32.8, 127.5, 92.8, 122, 129.6, 35.4, 20.6, 88, 14.8, 12.8, 33.8, 58.6, 104.2, 0.2)), class = "data.frame", row.names = c(NA, -88L))

代码:

library(ggplot2)
library(scales)
dat = read.csv('mo.csv')
p2=ggplot(dat, aes(x = dat$v2)) +
geom_histogram(color="black", fill="grey40", bins=25)+
scale_x_continuous(breaks = seq(0, 255, 25), limits = c(0,255), expand=c(0,0))+
scale_y_continuous(expand = c(0,0),limits = c(0,16.5), breaks = pretty(dat$v2, n = 140))
p2

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