I tried simply plotting some data in R with the y-axis label horizontal and left of the y-axis tick labels. I thought the code below would work:
set.seed(1) n.obs <- 390 vol.min <- .20/sqrt(252 * 390) eps <- rnorm(n = n.obs, sd = vol.min) mar.default <- c(5,4,4,2) + 0.1 par(mar = mar.default + c(0, 4, 0, 0)) # add space to LHS of plot pdf("~/myplot.pdf", width=5.05, height=3.8) plot(eps, main = "Hello World!", las=1, ylab="") # suppress the y-axis label mtext(text="eps", side=2, line=4, las=1) # add horiz y-axis label # 4 lines into the margin
Instead, as you may see, the y-axis label almost fell completely outside of the graphics window. This phenomenon still exists no matter how much I expand the LHS margin.
Q: What am I doing wrong? Is there something I need to do with the oma
parameter? What do I need to do to plot things the way I'm intending? I'm a little overwhelmed by all of this!
This is a classic one, maybe should be a FAQ. You have to set the par
settings after the call to pdf
, which creates the plotting device. Otherwise you're modifying the settings on the default device:
set.seed(1) n.obs <- 390 vol.min <- .20/sqrt(252 * 390) eps <- rnorm(n = n.obs, sd = vol.min) # add space to LHS of plot pdf("~/myplot.pdf", width=5.05, height=3.8) mar.default <- c(5,4,4,2) + 0.1 par(mar = mar.default + c(0, 4, 0, 0)) plot(eps, main = "Hello World!", las=1, ylab="") # suppress the y-axis label mtext(text="eps", side=2, line=4, las=1) dev.off()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With