ggplot中几何对象和统计变换对应表
绘图时用来计算新数据的算法称为 stat(statistical transformation, 统计变换)。
统计变换可以生成新的变量并在图形中展示。通过查看 stat 参数的默认值,你可以知道几何对象函数使用了哪种统计变换。例
如, ?geom_bar 显示出 stat 的默认值是 count,这说明 geom_bar() 使用 stat_count() 函数进行统计变换。 stat_count() 在文档中与 geom_bar() 位于同一页,如果继续向下看,你可以发现名为“Computed variables”的一节,它告诉我们 stat_count() 会计算出两个新变量: count 和 prop,图1。表1列出了所有的几何对象和统计变换的对应关系。
图1:stat_count()中的“Computed variables”
表1:ggplot中几何对象和统计变换对应表
geoms | stats | function |
geom_bar(),geom_col() | stat_count() | Bar charts |
geom_bin2d() | stat_bin_2d() | heatmap of 22d bin counts |
geom_boxplot() | stat_boxplot() | A box and whiskers plot (in the style of Tukey) |
geom_contour() geom_contour_filled() | stat_contour() stat_contour_filled() | 2D contours of a 3D surface |
geom_function() | stat_function(0 | Draw a function as a continuous curve |
geom_count() | stat_sum() | Count overlapping points |
geom_density() | stat_density() | Smoothed density estimates |
geom_density_2d() geom_density_2d_filled() | stat_density_2d() stat_density_2d_filled() | Contours of a 2D density estimate |
geom_hex() | stat_bin_hex() | Hexagonal heatmap of 2d bin counts |
geom_freqpoly() geom_histogram() | stat_bin() | Histograms and frequency polygons |
geom_qq_line() geom_qq() | stat_qq_line() stat_qq() | A quantile-quantile plot |
geom_quantile() | stat_quantile() | Quantile regression |
geom_smooth() | stat_smooth() | Smoothed conditional means |
geom_violin() | stat_ydensity() | Violin plot |
coord_sf() geom_sf() geom_sf_label() geom_sf_text() | stat_sf() | Visualise sf objects |
geom_pointrange() | stat_summary() | Various ways of representing a vertical interval defined by x, ymin and ymax. Each case draws a single graphical object. |
参考:https://ggplot2.tidyverse.org/reference/
R数据科学