pdf绘图设备的绘图边距:y轴标签落在图形窗口之外 [英] Plot margin of pdf plot device: y-axis label falling outside graphics window

查看:39
本文介绍了pdf绘图设备的绘图边距:y轴标签落在图形窗口之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试简单地在 R 中绘制一些数据,y 轴标签水平和 y 轴刻度标签的左侧.我认为下面的代码会起作用:

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

相反,如您所见,y 轴标签几乎完全落在图形窗口之外.无论我将 LHS 边距扩大多少,这种现象仍然存在.

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.

问:我做错了什么?我需要对 oma 参数做些什么?我需要做什么才能按照我想要的方式绘制事物?这一切让我有点不知所措!

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!

推荐答案

这是一个经典的,也许应该是一个FAQ.您必须在调用 pdf 之后设置 par 设置,这会创建绘图设备.否则,您正在修改默认设备上的设置:

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

这篇关于pdf绘图设备的绘图边距:y轴标签落在图形窗口之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆