2

How do I add dotted lines and horizontal bars at the end of the dotted lines to my boxplot in ggplot? By default it creates a vertical lines going out from the box. Please see example below how I want it:

here is my code

  p <- ggplot(data, aes(factor(Length,levels=18:26), logFC)) + 
         geom_boxplot(fill = "white") + 
         coord_cartesian(ylim=c(-5,5)) +
         theme_bw(base_size=45) + 
         scale_x_discrete("", breaks=factor(18:26), drop=FALSE) 

enter image description here

tonytonov
  • 25,060
  • 16
  • 82
  • 98
user3741035
  • 2,455
  • 4
  • 15
  • 20

1 Answers1

0

@CMichael cites the answer. This merely illustrates it. First, some toy data.

year <- rep("2014", 10)
total <- c(seq(55, 90, 5), 100, 40)
df <- data.frame(year = as.factor(year), total = total)

Then the plot, showing dotted lines and color.

ggplot(df, aes(x=factor(year), y=total)) + 
  geom_boxplot(linetype = "dotted", color = "red") +
  theme_bw()

enter image description here

lawyeR
  • 7,488
  • 5
  • 33
  • 63