PDF 54 / 520 chart, you can use one of three other options: "identity", "dodge" or "fill":
English · PDF 54
Original PDF page 54
中文 · PDF 54

图表,你可以使用另外三个选项之一:"identity"、"dodge" 或 "fill":

  • position = "identity" 会将每个对象精确地放置在图形上下文中它所在的位置。这对条形图来说不太有用,因为它会使条形相互重叠。要看到这种重叠效果,我们需要通过将 alpha 设置为一个较小的值使条形略微透明,或者通过设置 fill = NA 使条形完全透明:

ggplot( data = diamonds, mapping = aes(x = cut, fill = clarity) ) + geom_bar(alpha = 1/5, position = "identity") ggplot( data = diamonds, mapping = aes(x = cut, color = clarity) ) + geom_bar(fill = NA, position = "identity")

identity 位置调整方式对于二维几何对象(如点)更有用,它也是这些对象的默认值。

  • position = "fill" 的工作方式类似于堆叠,但会使每组堆叠的条形具有相同的高度。这使得跨组比较比例更加容易:

ggplot(data = diamonds) + geom_bar( mapping = aes(x = cut, fill = clarity), position = "fill" )