Plot margin of pdf plot device: y-axis label falling outside graphics window

后端 未结 1 443
广开言路
广开言路 2020-12-09 16:29

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)
         


        
相关标签:
1条回答
  • 2020-12-09 16:44

    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()
    

    enter image description here

    0 讨论(0)
提交回复
热议问题