0

I would like to create black outlines around my errorbars in order to get especially the white errorbar better visible (see attached code below).

I would be very grateful if anyone could help me (If of any help I can send the whole code & dput to the person who responds).

REPRODUCIBLE EXAMPLE

# 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))
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • 2
    [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – shekeine May 04 '15 at 07:36
  • 3
    The errorbars are lines. Lines don't have outlines. You could change the panel background or you could print the errorbars in black with a bigger `size` and then print them in the other colors on top. – Roland May 04 '15 at 07:58
  • Dear Roland, I make the errorbars a little bit wider so that they are not just lines (unfortunately I can't upload pictures since my "reputation" is too low here;/). Yes I read the idea with black errorbars several times but somehow it does not work when I do it (most likely I do something wrong). If you know how it should be done could you show me where and how I have to change my code? – Michael_Eisenring May 05 '15 at 04:08
  • I added a reproducible example at the end of the main post – Michael_Eisenring May 05 '15 at 20:30
  • Nice start with the reproducible example. Next time you share data for a plotting question, don't share raw data and 20 lines of code to transform it into shape for plotting. Just share the transformed data that's ready for plotting already. – Gregor Thomas May 05 '15 at 20:52

0 Answers0