我是ggplot2的新手,正在尝试获取与相同的直方图hist(results, breaks = 30)
。
如何使用ggplot2复制相同的直方图?我正在使用的binwidth
参数geom_histogram
,但是我很难使两个直方图看起来相同。
如果使用代码,您将看到R如何决定分解您的数据:
data(mtcars)
histinfo <- hist(mtcars$mpg)
从中,histinfo
您将获得有关休息的必要信息。
$breaks
[1] 10 15 20 25 30 35
$counts
[1] 6 12 8 2 4
$density
[1] 0.0375 0.0750 0.0500 0.0125 0.0250
$mids
[1] 12.5 17.5 22.5 27.5 32.5
$xname
[1] "mtcars$mpg"
$equidist
[1] TRUE
attr(,"class")
[1] "histogram"
>
现在,您可以调整下面的代码以使ggplot直方图看起来更像基础代码。您将不得不更改轴标签,比例和颜色。theme_bw()
将帮助您按顺序进行一些设置。
data(mtcars)
require(ggplot2)
qplot(mtcars$mpg,
geom="histogram",
binwidth = 5) +
theme_bw()
并将其binwidth
值更改为适合您的值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句