R geom_tile ggplot2应用了什么样的统计数据? [英] R geom_tile ggplot2 what kind of stat is applied?
问题描述
我在同一个图上使用了 geom_tile()
作为绘图3变量... with
tile_ruined_coop< -ggplot(data = df.1 [sel1,])+
geom_tile(aes(x =奖励,y = malus,fill = rf / 300))+
scale_fill_gradient(name =vr)+
facet_grid(Seuil_out_coop_i〜nb_coop_init)
tile_ruined_coop
,我对结果感到满意!
但是对 fill
应用了什么样的统计处理?这是一个意思吗?
要绘制填充值的平均值,您应该在绘制之前合计您的值。 scale_colour_gradient(...)不适用于数据级别,但在可视化级别上。
让我们从一个玩具Dataframe开始构建一个可重复使用的例子。
mydata = expand.grid(bonus = seq(0,1,0.25),malus = seq(0,1,0.25),type = c(Risquophile,Moyen,Risquophobe))
mydata = do.call(rbind ,复制(40,mydata,简化= FALSE))
mydata $ value = runif(nrow(mydata),min = 0,max = 50)
mydata $ coop =cooperative
现在,在绘图之前,我建议您计算40组值的平均值,并且对于此操作使用 dplyr 包:
library(dplyr)
data = mydata%> %group_by(bonus,malus,type,coop)%>%summarize(vr = mean(value))
您可以使用 ggplot2 准备好您的数据集:
<$ c $ b $ library bg = ggplot(data,aes(x = bonus,y = malus,fill = vr))
g = g + geom_tile()
g = g + facet_grid(类型〜coop)
这是结果:
您可以确定填充值恰好是您的值的平均值。
这是您的预期吗?
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
and I am pleased with the result !
But What kind of statistical treatment is applied to fill
? Is this a mean ?
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"
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))
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)
and this is the result:
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屋!