I'm having some trouble exporting a simple scatterplot to a pdf file in ggplot2. Specifically when I set the tick mark length to a negative value (essential), the tick mark labels merge with the axis line (as shown below).
The figure appears normally in the plot window of rstudio but when I export to pdf the problem occurs. Altering vjust
in axis.text.x
doesn't seem to be helping at all. I've also tried manipulating the plot margins.
Is anyone aware of a way of moving the labels away from the axis in such a situation?
Hopefully the code below should replicate the issue.
data = data.frame(xvar = seq(1:20), yvar = seq(1:20), labvar = rep(c("A", "B"), 10))
require(ggplot2)
require(gridExtra)
p <- ggplot(data = data, aes(x = xvar, y = yvar)) + geom_point() +
facet_wrap(~labvar, scales = "fixed") +
theme_classic()+
theme(axis.ticks.length=unit(-0.1, "cm"),
axis.text.x=element_text(vjust = 0))
p
vjust
doesn't work. Isunit(-0.05, "cm")
affordable? It fixed the overlapping for me. – tonytonov