我使用gpairs_lower
此答案中的函数仅显示ggpairs
绘图矩阵的下三角形。但现在我不知道如何保存结果图。
通常的方法来保存ggpairs
情节并没有在这里工作:
gpairs_lower <- function(g){
g$plots <- g$plots[-(1:g$nrow)]
g$yAxisLabels <- g$yAxisLabels[-1]
g$nrow <- g$nrow -1
g$plots <- g$plots[-(seq(g$ncol, length(g$plots), by = g$ncol))]
g$xAxisLabels <- g$xAxisLabels[-g$ncol]
g$ncol <- g$ncol - 1
g
}
library("GGally")
g <- ggpairs(iris[, 1:4],
lower = list(continuous = "points"),
upper = list(continuous = "blank"),
diag = list(continuous = "blankDiag")
)
png("graph.png", height = 720, width = 720)
gr <- gpairs_lower(g)
print(gr)
dev.off()
## graph.png is not saved
它不工作,我相信,因为gpairs_lower
相对于ggpairs
确实无法返回ggmatrix
的对象。
理查德任何帮助将不胜感激。
编辑:现在上面的代码有效!
您的代码的问题是高度和宽度的默认单位是像素,因此您要保存 7x7 像素的图像!!尝试其他值或更改units
:
png("myPlotMatrix.png", height = 700, width = 700)
g <- ggpairs(iris[, 1:4],
lower = list(continuous = "points"),
upper = list(continuous = "blank"),
diag = list(continuous = "blankDiag")
)
g<-gpairs_lower(g)
print(g)
dev.off()
看看?png
:
宽度:设备的宽度。
高度:设备的高度。
单位:给出高度和宽度的单位。可以是 px(像素,默认值)、in(英寸)、cm 或 mm。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句