0

Any ideas on how to solve the missialingment of text summary? why position_dodge works well for error_bar but not for text?? I have also tried position_dodge2. It also gives lots of problems with error_bar positions....

ggplot(data=data_areas[data_areas$TIMEPOINT=='0h',], aes(ISOFORM,NEURITE_CELL_AREA_RATIOP)) +
geom_bar(aes(fill=CELLTYPE,color=CELLTYPE), position=position_dodge(width=0.9, preserve = "single"), width=0.8,stat = 'summary', fun.y = 'mean') +
geom_errorbar(aes(color = CELLTYPE), stat = 'summary',position=position_dodge(width=0.9, preserve = "single"), width = 0.2,size=2, fun.data = "mean_sdl", fun.args = list(mult = 1)) + # mult indica el numero de desviaciones estandar
#geom_point(aes(group=CELLTYPE), shape = 21, position = position_dodge(.8), size=2, fill="gray")+
scale_x_discrete(expand = c(0.5,0.05))+
scale_y_continuous(expand = c(0.05,0), limits = c(0, 25), breaks = seq(0, 25, by = 5))+
scale_fill_manual(name="Celltype",values =c("#7d7973","#7d7973","#7d7973","#7d7973","#7d7973","#7d7973","#7d7973"))+
scale_color_manual(name="Celltype",values =c("#7d7973","#7d7973","#7d7973","#7d7973","#7d7973","#7d7973","#7d7973"))+
stat_summary(aes(label=round(..y..,2),group=CELLTYPE), fun.y=mean, geom="text", size=4,color="red",position=position_dodge(width=0.9, preserve='single'), vjust = 2)+
theme(axis.title.x = element_blank(),
      axis.title.y =element_blank(),
      axis.text.x  = element_blank(),
      axis.text.y  = element_blank(),
      plot.margin = margin(1, 1, 1, 1, "cm"),
      axis.line.y = element_line(colour = "black", size=1),
      axis.line.x =  element_line(colour = "black", size=1),
      axis.ticks = element_line(color = "black", size = 0.5),
      axis.ticks.length = unit(10, "pt"),
      axis.ticks.x = element_blank(),
      legend.position="none",
      panel.background = element_rect(fill = 'white'),
      panel.grid.major = element_line(colour = "#f0f0f0"))

plot obtained

2
  • Hello! Please provide the reproducible sample. Apr 20, 2020 at 12:46
  • Yes, a reproducible example would help. You could try `position_dodge2' as well perhaps. Sep 18, 2020 at 3:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.