如何在x轴上对直方图的条形对齐或居中?

时间:2022-06-01 14:57:37
qplot(carat,data=diamonds,geom="histogram",binwidth=1,xlim=c(0,3))

I use this code to draw a histogram. But the result is different from that of book.

我用这段代码绘制直方图。但结果与书的结果不同。

如何在x轴上对直方图的条形对齐或居中?

如何在x轴上对直方图的条形对齐或居中?

1 个解决方案

#1


2  

There are two possibilities, either use the center parameter as suggested by Richard Telford or the boundary parameter.

有两种可能性,要么使用Richard Telford建议的中心参数,要么使用边界参数。

Both codes below will create the same chart:

以下两个代码将创建相同的图表:

library(ggplot2)  # CRAN version 2.2.1 used
qplot(carat, data=diamonds, geom = "histogram", binwidth = 1, xlim = c(0,3),
      center = 0.5)
qplot(carat, data=diamonds, geom = "histogram", binwidth = 1, xlim = c(0,3),
      boundary = 0)

如何在x轴上对直方图的条形对齐或居中?

For more details, please, see ?geom_histogram.

有关详细信息,请参阅?geom_histogram。

#1


2  

There are two possibilities, either use the center parameter as suggested by Richard Telford or the boundary parameter.

有两种可能性,要么使用Richard Telford建议的中心参数,要么使用边界参数。

Both codes below will create the same chart:

以下两个代码将创建相同的图表:

library(ggplot2)  # CRAN version 2.2.1 used
qplot(carat, data=diamonds, geom = "histogram", binwidth = 1, xlim = c(0,3),
      center = 0.5)
qplot(carat, data=diamonds, geom = "histogram", binwidth = 1, xlim = c(0,3),
      boundary = 0)

如何在x轴上对直方图的条形对齐或居中?

For more details, please, see ?geom_histogram.

有关详细信息,请参阅?geom_histogram。