[英]Error with position dodge in ggplot2
我目前在使用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)))
但是當我運行它時,應該帶有我的barplot的窗口顯示為空白,並且彈出此錯誤消息
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)
的情況下運行它時,會出現一個條形圖,但這些條形位於均值的每個條形之間,而不在中間。
我已經嘗試了dodge
和其他東西的幾種價值,但我的想法已經用完了。
我收到一條警告,指出已應用“ 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))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.