R:ggplot2点范例 [英] R: ggplot2 pointrange example
问题描述
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屋!