1

Have created 3 graphs one for root area=proot one for leaf area=pleaf and one for soil area=psoil.

Each individually show the comparison statistics letter above the error bar but when i combine all 3 into one image using plot_grid it shows everything but the error bar. The combined plot created wont export properly but if i use the Zoom it displays correctly and i can take a screen clip.

Sorry I cannot provide reproducible sample the data does not belong to me and the scientist i am doing this for does not want me to post it.

Below find code that creates the last graph and the combination code:

proot <- ggplot(data=summary_meanbylocation_root, aes(x=substrate, y=mean, fill=location_plant)) + 
     geom_errorbar(aes(x=substrate, ymin=mean-SE, ymax=mean+SE), width=.2,position=position_dodge(.9))+

     geom_bar(stat="identity",position=position_dodge()) +

     facet_grid(~rearing) + theme_bw()+
     labs(title="Weevil mean on roots by Plant Selection based on rearing grain Dunn Test", x="Plant.Selection", y="Mean weevil roots", fill="sex") + 
     ylim(0,15)+
     theme(plot.title = element_text(size=15, margin=margin(t=20, b=20)))+
     theme(axis.text.x=axistext, axis.text.y=axistext,strip.text=element_text(size=13))+
     scale_fill_manual(values=c("grey", "black"), 
                       breaks=c("rmale", "rfemale"),
                       labels=c("male", "female"))
#Wilcoxon
#proot<-proot+geom_text(aes(label=c("a","a","c","b","a","a","a","a","a","a","ab","a","a","a","ab","a","a","a","bc","b","a","a","b","a","a","a","a","ab","a","a","a","a"),hjust=offset.h, vjust=offset.v),position=position_dodge(.9)) 
#
##Dunn
#
proot <-proot + geom_text(aes(x =substrate,y= mean+(SE+1),label=c("a","a","b","b","a","a","a","a","a","a","a","a","a","a","a","a","a","a","ab","b","a","a","a","a","a","a","a","ab","a","a","a","a")),position=position_dodge(.9)) 

print(proot)
----------------------------------------------------------
#combine into single graph ggarrange from gg pubr Pk

#ggarrange(pleaf, psoil, proot,ncol=1, nrow=3)

#Error?Error in -ggarrange(pleaf, psoil, proot, ncol = 1, nrow = 3) : 
#     invalid argument to unary operator


#worked but need to zoom in to see

# #combining using cowplot pk columns 1 3 ros
plot_grid(pleaf,psoil, ncol=1) #this wont export  correctly use  snip tool

#then load into windows drawing program and erase extras
#tried with  labels and it failed  dont know why so use  eraser and text fnction in draw


# Error in -plot_grid(pleaf, psoil, proot, labels = c("Fig A", "Fig B",  : 
#invalid argument to unary operator


[![exported with no zoom][1]][1]


[![zoomed image][2]][2]


  [1]: https://i.stack.imgur.com/nuh9N.jpg
  [2]: https://i.stack.imgur.com/t4ktM.jpg
MRomero
  • 13
  • 8
  • 1
    Can you provide a reproducible example of your data used to create this graph ? see here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – dc37 Jan 27 '20 at 19:21
  • have you tried your code in an empty session? It may be as simple as a not correctly defined object in `ggarrange`. Also, using `geom_text` with the label vector in `aes` like that is maybe less than ideal. Instead, `annotate` could be better – tjebo Jan 27 '20 at 21:53
  • I will upload the data and the script but something weird happened I have been trying things to align my letters directly above the error bar and i finally got it right but now both of the grouping methods i tried ggarrange and plot_grid give the same error "invalid argument to unary operator. – MRomero Jan 29 '20 at 15:03
  • Sorry for the questions i solved the problem just had to change (double the width and heght) in the export screen and then it exported correctly – MRomero Jan 29 '20 at 16:14

0 Answers0