What is the difference between geoms and stats in ggplot2?

前端 未结 3 793
再見小時候
再見小時候 2020-12-24 08:57

Both geoms and stats can be used to make plots in the R package ggplot2, and they often give similar results (e.g., geom_area and stat_bin). They also often have slightly di

3条回答
  •  滥情空心
    2020-12-24 09:23

    geoms stand for "geometric objects." These are the core elements that you see on the plot, object like points, lines, areas, curves.

    stats stand for "statistical transformations." These objects summarize the data in different ways such as counting observations, creating a loess line that best fits the data, or adding a confidence interval to the loess line.

    As geoms are the "core" of the plot, these are required objects. On the other hand, stats are not required to produce a plot, but can greatly enhance the final plot.

    As @eipi10 notes in the comments, these distinctions are somewhat conceptual as the majority of geoms undergo some statistical transformation prior to being plotted. These include geom_bar, geom_smooth, and geom_quantile. Some common exceptions where the data is presented in more or less "raw" form are geom_point and geom_line and the less commonly used geom_rug.

提交回复
热议问题