寻找一种使用铸造代码存储库将使用ggplot2的R脚本创建的可视化写入铸造厂文件系统的方法。
发布于 2022-05-25 15:35:22
问得好!这在这里的文档中得到了回答:https://www.palantir.com/docs/foundry/code-workbook/transforms-unstructured/#example-saving-a-plot-to-a-pdf可以写入输出FileSystem。这对于编写非表格数据格式(包括图像、PDF、文本文件等)非常有用。
调用new.output()实例化一个TransformOutput。了解有关FileSystem API的更多信息。
只能在保存为数据集的节点中使用TransformOutput编写文件。不能在控制台中使用TransformOutput编写文件。
下面是一个散点图的例子(保存到PDF中以保持良好的分辨率):
plot_pdf <- function() {
library(ggplot2)
theme_set(theme_bw()) # pre-set the bw theme
data("midwest", package = "ggplot2")
# Scatterplot
gg <- ggplot(midwest, aes(x=area, y=poptotal)) +
geom_point(aes(col=state, size=popdensity)) +
geom_smooth(method="loess", se=F) +
xlim(c(0, 0.1)) +
ylim(c(0, 500000)) +
labs(subtitle="Area Vs Population",
y="Population",
x="Area",
title="Scatterplot",
caption = "Source: midwest")
output <- new.output()
output_fs <- output$fileSystem()
pdf(output_fs$get_path("my pdf example.pdf", 'w'))
plot(gg)
}https://stackoverflow.com/questions/72379981
复制相似问题