Likan Zhan

ggplot2 包 position_dodge 命令中参数 width 什么意思

战立侃 · 2018-05-19

原文链接

  1. 看下面的图
df <- data.frame(x = 1, y = 1, grp = c("A", "B"))
DT::datatable(df, rownames = FALSE, width = 50, fillContainer = FALSE, options = list(pageLength = 8, searching = FALSE, info = FALSE, bLengthChange = FALSE))
  1. ggplot2 软件包中 position_dodge 命令的说明文档如下:
   width: Dodging width, when different to the width of the individual
          elements. This is useful when you want to align narrow geoms
     geom_bar(mapping = NULL, data = NULL, stat = "count",
       position = "stack", ..., width = NULL, binwidth = NULL, na.rm = FALSE,
       show.legend = NA, inherit.aes = TRUE)

   width: Bar width. By default, set to 90% of the resolution of the
          data.
Compute the "resolution" of a numeric vector
     The resolution is the smallest non-zero distance between adjacent
     values.  If there is only one unique value, then the resolution is
     defined to be one. If x is an integer vector, then it is assumed
     to represent a discrete variable, and the resolution is 1.
Details:

     Note the the "width" and "height" of a text element are 0, so
     stacking and dodging text will not work by default, and axis
     limits are not automatically expanded to include all text.
     Obviously, labels do have height and width, but they are physical
     units, not data units. The amount of space they occupy on that
     plot is not constant in data units: when you resize a plot, labels
     stay the same size, but the size of the axes changes.