r - pdf绘图设备的绘图边距: y-axis label falling outside graphics window

标签 r plot

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

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

my image

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

问:我做错了什么?我需要处理 oma 吗?范围?我需要做什么才能按照我的意图进行绘制?我对这一切有点不知所措!

最佳答案

这是一个经典的,也许应该是一个常见问题解答。您必须设置 par调用 pdf 后的设置,它创建了绘图设备。否则,您将修改默认设备上的设置:

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

关于r - pdf绘图设备的绘图边距: y-axis label falling outside graphics window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8100765/

相关文章:

r - 在 R 中展平嵌套 JSON

Matlab 绘图 : remove connecting line between disconnected regions?

r - 如何在 Shiny 中单击添加/保留任意数量的绘图层

r - 为什么 hexbin 对象上的 Graphics::plot 调用会抛出错误?

python - 使用 matplotlib 或 PIL 将 3d numpy 数组绘制为 3d 图像

r - facet_grid问题: input string 1 is invalid in this locale?

r - 使用 treemapify 在 R 中绘制 TreeMap

r - 创建一个绘制绘图并保存的函数

r - 从 PowerPivot 导出数据

matlab - 通过两点画一条线