错误:没有统计数据称为StatHline [英] Error: no stat called StatHline
问题描述
我有一个数据框如下:
variable = c(D,D,C ,C,C,A,B,B,B,B)
值= c(80,100,70,68,65,45,33,31 ,36,32)
Count = as.integer(c(5,10,4,5,2,7,3,5,6,2))
mean = c(93.3,93.3, 68.2,68.2,68.2,45,33.4,33.4,33.4,33.4)
sumVarVal = data.frame(variable = variable,value = value,Count = Count,mean = mean)
我可以做一个好的情节(其中平方的大小对应于具有特定x值和y值的观察次数),如下所示:
library(ggplot2)
ggplot(sumVarVal,aes(variable,value))+
geom_point(aes(size = Count),pch = 15)+
guides(fill = guide_legend(title =New))+
theme(legend.background = element_rect(fill = $
color =black),
legend.text = element_text(size = rel(1.3)),
legend.title = element_text(size = rel(1.3),face =plain),
legend.position =botto m,
axis.text = element_text(size = rel(1.3)),
axis.title = element_text(size = rel(1.3)))+
labs(x =学习结果,y =百分比等级)
但是,我以前有一个额外的代码(在语法结尾),允许我在四个主题中的每一个上叠加一个水平条,表示平均百分比等级。这些值存储在df $ mean中。这是我使用的代码:
ggplot(sumVarVal,aes(variable,value))+
geom_point aes(size = Count),pch = 15)+
guides(fill = guide_legend(title =New))+
theme(legend.background = element_rect(fill =gray90,size =
legend.text = element_text(size = rel(1.3)),
legend.title = element_text(size = rel(1.3),face =plain )
legend.position =bottom,
axis.text = element_text(size = rel(1.3)),
axis.title = element_text(size = rel(1.3))) +
labs(x =Learning Outcome,y =Percentage Grade)+
geom_errorbar(stat =hline,width = 0.6,color =blue,size = 1,aes ymax = .. y ..,ymin = .. y ..,yintercept = mean))
使用版本 1.0.1
,这将给出:
使用版本 2.0.0
,现在会导致错误:
错误:没有统计数据称为StatHline。
我知道这可能连接到ggplot2中的最新升级。我已经看到其他最近的评论(
似乎一些平均的蓝线不排在他们的价值观,原来在平均向量中给出。例如,对于变量D,它应该具有93.3的平均值,但蓝色水平线似乎显示为90.0的值。在我的实际代码(不是这个MWE)中,效果更加显着。任何想法可能导致这种差异?
stat_hline
I have a data frame as follows:
variable=c("D","D","C","C","C","A","B","B","B","B")
value=c(80,100,70,68,65,45,33,31,36,32)
Count=as.integer(c(5,10,4,5,2,7,3,5,6,2))
mean=c(93.3,93.3,68.2,68.2,68.2,45,33.4,33.4,33.4,33.4)
sumVarVal=data.frame(variable=variable,value=value,Count=Count,mean=mean)
I can make a nice plot (where the size of the square corresponds to the count of observations with that particular x-value and y-value), as shown below:
library(ggplot2)
ggplot(sumVarVal, aes(variable, value)) +
geom_point(aes(size = Count), pch=15) +
guides(fill=guide_legend(title="New")) +
theme(legend.background = element_rect(fill="gray90",
size=.5,
colour = "black"),
legend.text=element_text(size=rel(1.3)),
legend.title=element_text(size=rel(1.3), face="plain"),
legend.position="bottom",
axis.text = element_text(size=rel(1.3)),
axis.title = element_text(size = rel(1.3))) +
labs(x="Learning Outcome", y = "Percentage Grade")
However, I used to have an additional piece of code (at the end of the syntax) that allowed me to superimpose a horizontal bar on each of the four topics, indicating the mean percentage grade. Those values are stored in df$mean. Here is the code I was using:
ggplot(sumVarVal, aes(variable, value)) +
geom_point(aes(size = Count), pch=15) +
guides(fill=guide_legend(title="New")) +
theme(legend.background = element_rect(fill="gray90", size=.5, colour = "black"),
legend.text=element_text(size=rel(1.3)),
legend.title=element_text(size=rel(1.3), face="plain"),
legend.position="bottom",
axis.text = element_text(size=rel(1.3)),
axis.title = element_text(size = rel(1.3))) +
labs(x="Learning Outcome", y = "Percentage Grade") +
geom_errorbar(stat = "hline", width=0.6, colour = "blue", size = 1, aes(ymax=..y..,ymin=..y.., yintercept = mean))
With version 1.0.1
, this gives:
With version 2.0.0
, it now leads to an error:
Error: no stat called StatHline.
I know this may be connected to recent upgrades in ggplot2. I have seen other recent comments about it (geom_errorbar - "No stat called StatHline"). However, due to my code surrounding the use of stat="hline"
, when I tried some of these suggestions, I was not able to get my code to work either. Perhaps there is something I do not understand about my original code that is preventing me from being able to update this issue?
EDIT: I have taken into account some of the suggestions, and am currently using this code:
ggplot(sumVarVal, aes(variable, value)) +
geom_point(aes(size = Count), pch=15) +
guides(fill=guide_legend(title="New")) +
theme(legend.background = element_rect(fill="gray90", size=.5, colour = "black"),
legend.text=element_text(size=rel(1.3)),
legend.title=element_text(size=rel(1.3), face="plain"),
legend.position="bottom",
axis.text = element_text(size=rel(1.3)),
axis.title = element_text(size = rel(1.3))) +
labs(x="Learning Outcome", y = "Percentage Grade") +
geom_errorbar(stat = "summary", fun.y = "mean", width=0.6, colour = "blue", size = 1, aes(ymax=..y..,ymin=..y.., yintercept = mean))
This gives me an output that looks like this:
It seems that some of the mean blue lines are not lining up to their values, as given originally in the mean vector. For instance, for variable "D", it should have a mean value of 93.3, but the blue horizontal line seems to be displayed at a value of 90.0. The effect is even more dramatic in my real code (not this MWE). Any ideas what might be causing this discrepancy?
stat_hline
got removed in ggplot2 2.0.0, but never fear; it wasn't really necessary anyway. If you remove the stat
argument entirely, it will default to identity
, which is fine. (summary
can work, too, if you prefer.) You need to change the aes
mapping, though, changing yintercept
to y
to account for the new stat
.
All together,
ggplot(sumVarVal, aes(variable, value)) +
geom_point(aes(size = Count), pch=15) +
guides(fill=guide_legend(title="New")) +
theme(legend.background = element_rect(fill="gray90", size=.5, colour = "black"),
legend.text=element_text(size=rel(1.3)),
legend.title=element_text(size=rel(1.3), face="plain"),
legend.position="bottom",
axis.text = element_text(size=rel(1.3)),
axis.title = element_text(size = rel(1.3))) +
labs(x="Learning Outcome", y = "Percentage Grade") +
geom_errorbar(width=0.6, colour = "blue", size = 1, aes(ymax=..y.., ymin=..y.., y = mean))
produces
这篇关于错误:没有统计数据称为StatHline的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!