0

这是我的代码:

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

lowerupper在上面的代码中定义为:

se0 <- 1.96 * sd(simple$int.0) / sqrt(length(simple$int.0))

lower <- mean(simple$int.0) - se0
upper <- mean(simple$int.0) + se0

非常感谢!

4

1 回答 1

0
simple$nOnset.fin <- factor(simple$nOnset.fin)
simple$stress <- factor(simple$stress, levels=ordered(c('1', '2', '3')))
simple$se <- 1.96 * sd(simple$int.0) / sqrt(length(simple$int.0))
simple$lower <- mean(simple$int.0) - se0
simple$upper <- mean(simple$int.0) + se0

library(ggplot2)
library(scales)
ggplot(
  data = simple, 
  aes(x = nOnset.fin, fill = stress)
) +
  geom_bar(position = 'fill') + 
  geom_errorbar(aes(ymin = lower, ymax = upper)) + 
  scale_fill_manual(values=colours.fin) + 
  scale_y_continuous("", labels = percent) + 
  xlab('Size') + 
  theme_bw() +  
  theme(
    text = element_text(size=35, family="CMU Sans Serif"), 
    legend.position = 'none'
  )




library(fortunes)
fortune("tested solution")

Tested solutions offered when reproducible examples are provided.
   -- David Winsemius (suggesting a potential solution to a vague problem description)
      R-help (April 2011)
于 2014-03-24T12:27:20.190 回答