ggplot2:如何将黑色轮廓添加到错误栏a

时间:2015-05-04 03:41:29

标签: r ggplot2

我想在我的错误栏周围创建黑色轮廓,以便更好地看到白色错误栏(请参阅下面的附件代码)。

如果有人能帮助我,我将非常感激(如果有任何帮助,我可以将整个代码和输出发送给回复的人)。

可重复的例子

# DATA:
structure(list(damage = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L), .Label = c("C", "L1", "L4"), class = "factor"), 
leaf = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 
4L, 4L, 5L, 5L, 5L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 
4L, 4L, 5L, 5L, 5L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 
4L, 4L, 5L, 5L, 5L), .Label = c("Cot", "L1", "L2", "L3", 
"L4"), class = "factor"), cor_average = c(587.6666667, 595.3333333, 
858, 2361.666667, 2880, 2760, 2338.333333, 2006.666667, 3296.666667, 
3660.333333, 2765, 3752, 3927.333333, 3705, 4636.666667, 
742.5, 605, 520, 1974, 2408, 2494, 2102.333333, 2470, 2701, 
3336.666667, 3737, 4529.666667, 4850, 4293.333333, 4972, 
487.5, 645, 623.3333333, 1998.333333, 2016.666667, 1971.666667, 
2520, 2532.333333, 2181.666667, 3720, 4275, 4389, 5625, 6303.333333, 
4783.666667)), .Names = c("damage", "leaf", "cor_average"
), class = "data.frame", row.names = c(NA, -45L))

#CODE
data <- read.csv("Example.csv",sep=",",header=T)
library(ggplot2)

summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE,
                  conf.interval=.95, .drop=TRUE) {
library(plyr)

 length2 <- function (x, na.rm=FALSE) {
    if (na.rm) sum(!is.na(x))
   else       length(x)
   }

   datac <- ddply(data, groupvars, .drop=.drop,
               .fun = function(xx, col) {
                 c(N    = length2(xx[[col]], na.rm=na.rm),
                   mean = mean   (xx[[col]], na.rm=na.rm),
                   sd   = sd     (xx[[col]], na.rm=na.rm)
                 )
               },
               measurevar
   )

   datac <- rename(datac, c("mean" = measurevar))

   datac$se <- datac$sd / sqrt(datac$N)  
   ciMult <- qt(conf.interval/2 + .5, datac$N-1)
   datac$ci <- datac$se * ciMult

   return(datac)
 }

CI <- summarySE(data, measurevar="cor_average", 
                groupvars=c("damage","leaf"))
CI

data$leaf <- ordered(data$leaf, levels = c("L4", "L3", "Cot","L1", "L2"))

pd <- position_dodge(0.4)

ggplot(CI, aes(x=leaf, y=cor_average, colour=damage)) +
  geom_errorbar(aes(ymin=cor_average-ci, ymax=cor_average+ci),
                width=.4, size=1.2,position=pd) +
  geom_line(position=pd) +
  scale_colour_manual(values=c("white","black","gray65"))+
  geom_point(position=pd,size=4.4)+
  labs(x="Leaf",y="Average nr. glands corrected for leaf sz.")+
  theme(axis.text=element_text(size=13),
        axis.title=element_text(size=16,face="bold"))+
  theme(legend.text = element_text(size=14),
        legend.title = element_text(size=14))

0 个答案:

没有答案