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?