首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在R中保存ggtern图

在R中保存ggtern图
EN

Stack Overflow用户
提问于 2021-09-04 04:29:01
回答 1查看 70关注 0票数 0

为了将情节保存为png或svg,应该添加什么服务器?

ggsave和ggtern一起工作吗?(这是对三元地块的to图的扩展)

下面是我试图在闪亮中所做的事情的一个最小的可重复的例子:

代码语言:javascript
复制
library(shiny)
library(ggtern)
library(tidyverse)



ui <- fluidPage(

    downloadButton("dwnld", label = "Save plot"),
    plotOutput("ternary")
)


server <- function(input, output) {
    # ternary plot via ggtern
    output$ternary <- renderPlot({
        data <- tibble(x = 0.2, y = 0.3, z = 0.5)
        plot <- ggtern(data, aes(x = x, y = y, z = z)) + geom_point(size = 8)
        print(plot)
        
    })
    
    # download the plot
    #????????
}

 
shinyApp(ui = ui, server = server)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-06 07:30:30

你可以按以下方式进行:

代码语言:javascript
复制
myPlot <- reactive({
  data <- tibble(x = 0.2, y = 0.3, z = 0.5)
  ggtern(data, aes(x = x, y = y, z = z)) + geom_point(size = 8)
})

output[["ternary"]] <- renderPlot({
  myPlot()
})

output[["dwnld"]] <- downloadHandler(
  filename = "myPlot.png",
  content = function(file){
    ggsave(file, myPlot())
  }
)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69052423

复制
相关文章

相似问题

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