首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在palantir铸造厂的文件系统中写入ggplot图表?

如何在palantir铸造厂的文件系统中写入ggplot图表?
EN

Stack Overflow用户
提问于 2022-05-25 14:59:11
回答 1查看 112关注 0票数 1

寻找一种使用铸造代码存储库将使用ggplot2的R脚本创建的可视化写入铸造厂文件系统的方法。

EN

回答 1

Stack Overflow用户

发布于 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中以保持良好的分辨率):

代码语言:javascript
复制
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)
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72379981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档