【发布时间】:2014-03-23 18:59:04
【问题描述】:
这是我的代码:
ggplot(data=simple, aes(x=as.factor(nOnset.fin),
fill=simple$stress <- factor(simple$stress, levels=ordered(c('1', '2', '3'))))) +
geom_bar(position = 'fill') +
scale_fill_manual(aes(Stress), values=colours.fin,
breaks = levels(simple$stress <- factor(simple$stress, levels=ordered(c('1', '2', '3'))))) +
scale_y_continuous(labels=percent_format()) + theme_bw() + xlab('Size') + ylab(NULL) +
theme(text=element_text(size=35, family="CMU Sans Serif"), legend.position = 'none')
这是生成的情节:
https://copy.com/ghLt3z0iORicZtup
我的问题很简单:如何将误差线添加到较深的蓝色条中(较浅的两个条在这里无关紧要)。我一直在尝试这个:
+ geom_errorbar(aes(ymin=lower, ymax=upper, x=as.factor(nOnset.fin)))
这是我遇到的错误:
错误:美学长度必须为 1,或与 dataProblems:lower,upper
上面代码中的lower和upper定义为:
se0 <- 1.96 * sd(simple$int.0) / sqrt(length(simple$int.0))
lower <- mean(simple$int.0) - se0
upper <- mean(simple$int.0) + se0
非常感谢!
【问题讨论】:
-
A
dput()的变量将有助于重现您当前的结果。 -
映射美学(
aes内部的那些需要是数据框中的列,或者它们的简单转换)。 Set 美学(aes()的outside)需要是单个值。也许您打算将stress转换为first 因子,然后将填充映射到压力?在ggplot调用中使用<-确实很奇怪。