1

I´d made a Y-maze experiment, where values goes to 0 (total preference to stimulus A) to 1 (total preference to stimulus B), index response is calculated as : # flies on stimulus B/(# flies stimulus A+B)

A 0.5 value means no differential election (a 50-50 random distribution) I need to make a diverging plot with means very similar to this with ggplot2:

enter image description here

NOTE: y-values starts from 0.5, what i want to make is the horizontal line in y=0.5, and that the bars starts from 0.5

here´s some of my data:

data<-data.frame(Line= c(21,181,208,217), mean= c(0.584, 0.897, 0.345, 0.67)
data$Linea<-as.factor(data$Line)

What I have tried is this code:

data$category<- ifelse(data$mean >0.5, "grape","apple")

ggplot(data,aes(x = Line ,y =mean)) + 
  geom_bar(aes(fill = category),stat = "identity") +
  labs(title= "Diverging Bars")+
  ylim(0,1)+ geom_hline(yintercept = 0.5)

and what I had is this: enter image description here

aleksandrbel
  • 1,422
  • 3
  • 20
  • 38
satower
  • 13
  • 4
  • 2
    Would you provide some data with `dput` and code you have tried? – acylam May 30 '18 at 19:59
  • Possibly what you're looking for: https://stackoverflow.com/questions/48794575/how-to-start-ggplot2-geom-bar-from-different-origin – Amanda May 31 '18 at 00:10

0 Answers0