ggplot2中的geoms和stats有什么区别? [英] What is the difference between geoms and stats in ggplot2?

查看:225
本文介绍了ggplot2中的geoms和stats有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

geom和stats均可用于在R包ggplot2中绘制图,并且它们通常给出相似的结果(例如geom_area和stat_bin).他们通常也有稍微不同的论点,例如在二维密度图:

geom_density_2d(mapping = NULL, data = NULL, stat = "density2d",
  position = "identity", ..., lineend = "butt", linejoin = "round",
  linemitre = 1, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)

stat_density_2d(mapping = NULL, data = NULL, geom = "density_2d",
  position = "identity", ..., contour = TRUE, n = 100, h = NULL, na.rm =
  FALSE, show.legend = NA, inherit.aes = TRUE)

两种类型的对象之间有根本区别吗?

解决方案

geom代表几何对象".这些是您在图上看到的核心元素,是点,线,面积,曲线之类的对象.

stats代表统计转换".这些对象以不同的方式汇总数据,例如对观测值进行计数,创建最适合数据的黄土线或为黄土线添加置信区间.

由于几何是图的核心",因此它们是必需的对象.另一方面,不需要统计数据即可生成情节,但可以极大地增强最终情节.

正如@ eipi10在评论中指出的那样,这些区别在概念上是很重要的,因为大多数几何图形在绘制之前都会进行一些统计转换.这些包括geom_bargeom_smoothgeom_quantile. geom_pointgeom_line以及不太常用的geom_rug.数据以或多或少的原始"形式显示的一些常见例外.

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 different arguments, e.g. in 2-D density plots:

geom_density_2d(mapping = NULL, data = NULL, stat = "density2d",
  position = "identity", ..., lineend = "butt", linejoin = "round",
  linemitre = 1, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)

stat_density_2d(mapping = NULL, data = NULL, geom = "density_2d",
  position = "identity", ..., contour = TRUE, n = 100, h = NULL, na.rm =
  FALSE, show.legend = NA, inherit.aes = TRUE)

Are there any fundamental differences between the two types of objects?

解决方案

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.

这篇关于ggplot2中的geoms和stats有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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