R:ggplot2点范例 [英] R: ggplot2 pointrange example

查看:189
本文介绍了R:ggplot2点范例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在阅读Hadley Wickham的 R for Data Science 。在这个例子中,有以下例子:

pre $ library $ t
$ b $ ggplot(data = diamonds )+
stat_summary(
mapping = aes(x = cut,y = depth),
fun.ymin = min,
fun.ymax = max,
fun .y = median

现在,如何创建相同的问题通过使用适当的 geom _ 函数进行绘图。我查看了 stat_summary 的默认 geom ,它是点范围



所以我尝试了以下方法:

  ggplot(data =钻石)+ geom_pointrange(mapping = aes(x = cut,y = depth),stat =summary)

但是我没有得到图上的 min max 点。



如何通过使用 geom_pointrange

解决方案

geom_pointrange 不会自动计算ymin或ymax值。您可以在使用 geom_pointrange 时完成 stat =summary

  ggplot(data = diamonds)+ 
geom_pointrange(mapping = aes(x = cut,y = depth),
stat =summary ,
fun.ymin = min,
fun.ymax = max,
fun.y = median)


I am currently reading R for Data Science by Hadley Wickham. In that, there is the following example:

library(tidyverse)

ggplot(data = diamonds) + 
stat_summary(
    mapping = aes(x = cut, y = depth),
    fun.ymin = min,
    fun.ymax = max,
    fun.y = median
)

Now, there is a question as how to create the same plot by using appropriate geom_ function. I looked at the default geom for stat_summary and it is pointrange.

So I tried the following:

ggplot(data = diamonds) + geom_pointrange(mapping = aes(x = cut, y = depth), stat = "summary")

But I do not get the min and max points on the plot.

How do I get the exact plot by using geom_pointrange?

解决方案

geom_pointrange does not automatically compute the ymin or ymax values. You can do this with stat = "summary" while still using geom_pointrange:

ggplot(data = diamonds) +
  geom_pointrange(mapping = aes(x = cut, y = depth),
                  stat = "summary",
                  fun.ymin = min,
                  fun.ymax = max,
                  fun.y = median)

这篇关于R:ggplot2点范例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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