将 par(mfrow) 多面板输出保存为 svg
Save par(mfrow) multipanel output as svg
我正在使用 par(mfrow) 生成三个独立图形输出对象的多面板图。下面的示例代码代表了我拥有的对象的一个非常简化的版本。
如何使用 ggsave 将这些绘图保存为单个对象?我试过将 par(mfrow) 命名为一个对象并绘制它,但这似乎不起作用。
也欢迎就 generating/saving 多面板图的替代方法提出任何建议!如果我可以澄清问题或示例,请告诉我。谢谢!
par(mfrow = c(1,3), mar = c(10, 5, 5, 3), xpd = TRUE)
hist(x = rnorm(100), col = "skyblue", main = "X")
hist(x = rnorm(50), col = "green", main = "Y")
legend("bottom", c("Blue", "Green", "Purple"),
title = "Sample Data", horiz = TRUE, inset = c(0, -0.4),
col = c("skyblue", "green", "purple"), pch = rep(15,2),
bty = "n", pt.cex = 1.5, text.col = "black")
hist(x = rnorm(75), col = "purple", main = "Z")
如果您想使用 Inkscape 或类似程序编辑图表,我建议您使用 svglite
而不是 svg
,因为您将无法编辑文本(更改文本、字体、或大小)在 svg
生成的文件中。这是一个对您的原始代码进行了一些编辑的示例:
library(svglite)
svglite("MyPlots.svg", width=8, height=6)
par(mfrow = c(1,3), mar = c(10, 5, 5, 3), xpd = TRUE, mgp=c(1.75, .75, 0))
hist(x = rnorm(100), col = "skyblue", main = "X")
hist(x = rnorm(50), col = "green", main = "Y")
legend("bottom", c("Blue", "Green", "Purple"),
title = "Sample Data", horiz = TRUE, inset = c(0, -0.2),
col = c("skyblue", "green", "purple"), pch = rep(15,2),
bty = "n", pt.cex = 1.5, text.col = "black")
hist(x = rnorm(75), col = "purple", main = "Z")
dev.off()
我正在使用 par(mfrow) 生成三个独立图形输出对象的多面板图。下面的示例代码代表了我拥有的对象的一个非常简化的版本。
如何使用 ggsave 将这些绘图保存为单个对象?我试过将 par(mfrow) 命名为一个对象并绘制它,但这似乎不起作用。
也欢迎就 generating/saving 多面板图的替代方法提出任何建议!如果我可以澄清问题或示例,请告诉我。谢谢!
par(mfrow = c(1,3), mar = c(10, 5, 5, 3), xpd = TRUE)
hist(x = rnorm(100), col = "skyblue", main = "X")
hist(x = rnorm(50), col = "green", main = "Y")
legend("bottom", c("Blue", "Green", "Purple"),
title = "Sample Data", horiz = TRUE, inset = c(0, -0.4),
col = c("skyblue", "green", "purple"), pch = rep(15,2),
bty = "n", pt.cex = 1.5, text.col = "black")
hist(x = rnorm(75), col = "purple", main = "Z")
如果您想使用 Inkscape 或类似程序编辑图表,我建议您使用 svglite
而不是 svg
,因为您将无法编辑文本(更改文本、字体、或大小)在 svg
生成的文件中。这是一个对您的原始代码进行了一些编辑的示例:
library(svglite)
svglite("MyPlots.svg", width=8, height=6)
par(mfrow = c(1,3), mar = c(10, 5, 5, 3), xpd = TRUE, mgp=c(1.75, .75, 0))
hist(x = rnorm(100), col = "skyblue", main = "X")
hist(x = rnorm(50), col = "green", main = "Y")
legend("bottom", c("Blue", "Green", "Purple"),
title = "Sample Data", horiz = TRUE, inset = c(0, -0.2),
col = c("skyblue", "green", "purple"), pch = rep(15,2),
bty = "n", pt.cex = 1.5, text.col = "black")
hist(x = rnorm(75), col = "purple", main = "Z")
dev.off()