R geom_tile ggplot2 应用了什么样的统计数据? [英] R geom_tile ggplot2 what kind of stat is applied?
问题描述
我使用 geom_tile()
在同一张图上绘制 3 个变量......使用
I used geom_tile()
for plot 3 variables on the same graph... with
tile_ruined_coop<-ggplot(data=df.1[sel1,])+
geom_tile(aes(x=bonus, y=malus, fill=rf/300))+
scale_fill_gradient(name="vr")+
facet_grid(Seuil_out_coop_i ~ nb_coop_init)
tile_ruined_coop
我对结果很满意!
但是对 fill
应用了什么样的统计处理?这是一个意思吗?
But What kind of statistical treatment is applied to fill
? Is this a mean ?
推荐答案
要绘制填充值的平均值,您应该在绘制之前聚合您的值.scale_colour_gradient(...) 不适用于数据级别,但适用于可视化级别.让我们从一个玩具 Dataframe 开始,构建一个可重现的示例来使用.
To plot the mean of the fill values you should aggregate your values, before plotting. The scale_colour_gradient(...) does not work on the data level, but on the visualization level. Let's start with a toy Dataframe to build a reproducible example to work with.
mydata = expand.grid(bonus = seq(0, 1, 0.25), malus = seq(0, 1, 0.25), type = c("Risquophile","Moyen","Risquophobe"))
mydata = do.call("rbind",replicate(40, mydata, simplify = FALSE))
mydata$value= runif(nrow(mydata), min=0, max=50)
mydata$coop = "cooperative"
现在,在绘图之前,我建议您计算 40 个值的组的平均值,并且对于此操作,例如使用 dplyr 包:
Now, before plotting I suggest you to calculate the mean over your groups of 40 values, and for this operation like to use the dplyr package:
library(dplyr)
data = mydata %>% group_by("bonus","malus","type","coop") %>% summarise(vr=mean(value))
您已经准备好使用 ggplot2 绘制数据集:
Tow you have your dataset ready to plot with ggplot2:
library(ggplot2)
g = ggplot(data, aes(x=bonus,y=malus,fill=vr))
g = g + geom_tile()
g = g + facet_grid(type~coop)
结果如下:
您确定填充值正是您的值的平均值.
这是您所期望的吗?
where you are sure that the fill value is exactly the mean of your values.
Is this what you expected?
这篇关于R geom_tile ggplot2 应用了什么样的统计数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!