gpt4 book ai didi

r - ggplot2 中位置闪避错误

转载 作者:行者123 更新时间:2023-12-01 16:43:07 25 4
gpt4 key购买 nike

我目前在使用 ggplot2 时遇到错误。我想使用此数据框创建带有标准误差条的条形图:

       mean        se       pattern quality
1 54.955357 19.792315 spread good
2 54.506944 18.580981 clumped good
3 29.604167 14.937291 centered good good
5 23.300595 14.336305 spread bad
6 8.371528 5.960366 clumped bad
7 16.364583 11.525207 centered good bad
8 7.062500 11.125915 centered bad bad

我使用这个公式来创建我的条形图:

ggplot(table, aes(x=pattern, y=mean, fill=quality))+
geom_bar(position="dodge")+
geom_errorbar(aes(ymin=mean-se, ymax=mean+se,
width=0.2, position=position_dodge(0.9)))

但是当我运行它时,应该包含条形图的窗口显示为空白,并弹出此错误消息

Don't know how to automatically pick scale for object of type proto/environment. Defaulting to continuous
Error : Aesthetics must either be length one, or the same length as the dataProblems:position_dodge(0.9)

当我尝试在没有 position=position_dodge(0.9) 的情况下运行它时,会出现一个条形图,但条形图位于每个均值条形图之间,而不是在中间。

我已经尝试了闪避和其他东西的几种值,但我已经没有想法了。

最佳答案

我收到一条警告,指出应用了“stat_identity”(映射到值,而不是计数)。要防止出现该警告,只需将 stat="identity" 添加到 geom 即可。

te <- c("val mean se pattern quality", 
"1 54.955357 19.792315 spread good",
"2 54.506944 18.580981 clumped good",
"3 29.604167 14.937291 centered_good good",
"5 23.300595 14.336305 spread bad",
"6 8.371528 5.960366 clumped bad",
"7 16.364583 11.525207 centered_good bad",
"8 7.062500 11.125915 centered_bad bad")

df <- read.table(text=te, header=T)

require(ggplot2)

ggplot(df, aes(x=pattern, y=mean, fill=quality))+
geom_bar(position="dodge", stat="identity")+
geom_errorbar(aes(ymin=mean-se, ymax=mean+se),
width=0.2, position=position_dodge(0.9))

enter image description here

关于r - ggplot2 中位置闪避错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23385270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com