如何在x轴上对齐或居中直方图的条形图? [英] How to align or center the bars of a histogram on the x axis?

查看:869
本文介绍了如何在x轴上对齐或居中直方图的条形图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  qplot(carat,data = diamonds,geom =histogram,binwidth = 1,xlim = c(0,3))

我使用此代码绘制直方图。但结果与书中的结果不同。





有两种可能性,可以使用中心参数作为 理查德·特尔福德建议或边界参数。



下面的两个代码都会创建相同的图表:

<$ p $ c $ library $($ g code> 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)



有关更多详情,请参阅?geom_histogram


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.

解决方案

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

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)

For more details, please, see ?geom_histogram.

这篇关于如何在x轴上对齐或居中直方图的条形图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆