【问题标题】:Labels and legend do not appear when saving a postscript file in R在 R 中保存后记文件时不显示标签和图例
【发布时间】:2018-07-04 10:15:20
【问题描述】:

我正在尝试使用dev.copy2eps() 函数来保存我输出的图表。但是,当我在函数中更改绘图宽度和高度时,所有字符串(包括标签和图例)都不会出现。

输出图的示例(具有非默认大小):

代码:

boxplot(volunteers$number_of_commits, employees$number_of_commits, las = 1, outline = FALSE, cex.lab=1.2, horizontal = TRUE, margin = list(l = 10, r = 10, b = 0, t = 0), col=(c("#b8d1ed", "#aae0c0")), main = "Number of Commits")
legend("bottomright", legend=c("Employees", "Volunteers"), fill=c("#aae0c0", "#b8d1ed"), inset= .02, cex=1.1)
dev.copy2eps(file="Images/atom/atom_num_commits.eps", width = 650, height = 360)

问题是:如何使用 postscript 功能保存不同大小的图表,同时保持相同的质量和信息?

【问题讨论】:

标签: r


【解决方案1】:

简而言之:您的heightwidth 参数似乎是问题所在。

事实证明,如果添加heightwidth,标签不会被删除但非常小。通过删除这些,您将能够看到 eps 中的标签,或者考虑使用明显更小的值。

plot(cars$speed~cars$dist)
legend("bottomright", legend=c("Employees", "Volunteers"), fill=c("#aae0c0", "#b8d1ed"), inset= .02, cex=1.1)
dev.copy2eps(file = "your_path/test.eps")

EPS 绘图的输出将具有与绘图设备(在 RGUI 或 RStudio 中)相同的高宽比。您可以添加参数以保持纵横比,但减小其值的大小。请参阅?dev.copy2eps的此部分:

如果dev.print 用于指定的设备(甚至postscript),它会以与dev.copy2eps 相同的方式设置宽度和高度。除非设备以英寸为单位指定尺寸,否则这是不合适的,特别是不适用于 pngjpegtiffbmp,除非指定了 units = "inches"

另一种解决方案,你也可以直接调整宽度和高度(以英寸为单位,所以你可能会想到大小)was proposedwas proposeds.brunel的评论:

setEPS()
postscript("C:/Users/weig_mi/Desktop/test2.eps", width = 6.5, height = 3.60)
plot(cars$speed~cars$dist)
legend("bottomright", legend=c("Employees", "Volunteers"), fill=c("#aae0c0", "#b8d1ed"), inset= .02, cex=1.1)
dev.off()

?postscript 我们得知widthheight

图形区域的宽度和高度,以英寸为单位。

【讨论】:

    猜你喜欢
    • 2016-03-18
    • 2014-06-30
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-04
    • 1970-01-01
    相关资源
    最近更新 更多