0

My intention is to increase space between the y-axis title and the tick labels when using ggplot. My code is:

ggplot(krc2.long.edited, aes(x=factor(OL), 
                           y=pi, fill=factor(mm, levels=c("NOL_piN","NOL_piS","OL_piN","OL_piS")), order=desc(mm))) + 
  geom_bar(stat="identity", position="stack",colour="black") + 
  scale_fill_manual(labels=c(expression(italic('π')[N-NOL]),expression(italic('π')[S-NOL]),
                             expression(italic('π')[N-OL]),expression(italic('π')[S-OL])),
                    values=c("#DE2D26","#3182BD","#FC9272","#9ECAE1")) + 
  guides(fill=guide_legend(title=NULL,override.aes = list(colour = NULL))) + 
  ylab("Nucleotide Diversity") + 
  theme_bw() + 
  theme(panel.grid.major=element_blank(), panel.grid.minor=element_blank(), 
        plot.margin=unit(c(1, 1, 0.5, 1), "lines"), axis.title=element_text(size=14), axis.title.x=element_blank(), 
        axis.title.y=element_text(vjust=1,margin=margin(0,20,0,0)), axis.text=element_text(size=14), axis.text.x=element_blank(), 
        axis.ticks.x=element_blank(), legend.title=element_text(face="bold",size=14), 
        legend.text=element_text(size=16), legend.text.align=0, legend.position=c(0.205,0.9), 
        legend.justification=c(1,1), legend.background=element_rect(fill="white",colour="black"), 
        legend.key = element_rect(colour = "black", size=1)) + 
  facet_grid(~ product, scales="free_x", drop=TRUE) + 
  theme(strip.text.x=element_text(size=17)) + geom_blank()

I attempt to add this space within theme() above using

axis.title.y=element_text(vjust=1,margin=margin(0,20,0,0))

My problem is the following error:

Error in element_text(vjust = 1, margin = margin(0, 20, 0, 0)) : unused argument (margin = margin(0, 20, 0, 0))

I have taken the step of removing and re-installing the latest ggplot2 library and restarting R, but I still get the same error as above. When I look at the help for element_text(), by typing ?element_text, no margin argument is in the documentation, either. What am I doing wrong?

Cyrus Mohammadian
  • 4,982
  • 6
  • 33
  • 62
Chase
  • 11
  • 1
  • 4
  • please include the data and the code that produces this error – mtoto Mar 15 '16 at 18:45
  • 2
    It would be nice if you can include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it easier for others to help you. – Jaap Mar 15 '16 at 18:47
  • you don't seem to have the latest ggplot2 – baptiste Mar 15 '16 at 19:19
  • try using margin using `c(0, 20, 0, 0)` only – TheRimalaya Mar 15 '16 at 21:13
  • Thank you all for your help. I think baptiste is correct—I have confirmed that, despite removal and re-installing, the ggplot2 package I have is v1. Unfortunately, installing a more recent version of R seems necessary to get v2—is that correct?—and some of my GIS applications were running into trouble when I installed a more recent version, so I guess I'll just have to wait. – Chase Mar 22 '16 at 17:11

0 Answers0