【问题标题】:R googleVis to png fileR googleVis到png文件
【发布时间】:2016-02-06 09:30:17
【问题描述】:

我有以下代码可以正常工作。我想知道是否可以将其导出为 png 文件。任何人都知道一个简单的方法来做到这一点。我才刚刚开始接触 R 世界,所以是个菜鸟。

这是我的代码

library(RODBC)
library(googleVis)

con <- odbcConnect("Live", uid="Rxyzuser", pwd="xxxxx")
attendees <- sqlQuery(con, "exec rpt_r_vis")

regCal <- gvisCalendar(attendees, 
                       datevar="Reg_add_date", 
                       numvar="Counts",
                       options=list(
                         title = "Registrations per Day Heatmap",
                         height = 400, width=1000,
                         calendar="{yearLabel: { fontName: 'Times-Roman',
                                    fontSize: 32, color: '#1A8663', bold:     true}, cellSize: 15,
                                    cellColor: { stroke: 'red', strokeOpacity: 0.2 },
                                    focusedCellColor: {stroke: 'red'}}")
  )
plot(regCal)


odbcCloseAll()

【问题讨论】:

    标签: r export png googlevis


    【解决方案1】:

    你试过了吗:

    png("sample.png",width = 480, height = 480, units = "px")
    plot(regCal)
    dev.off()
    

    最好的,

    罗伯特

    【讨论】:

    • 某种作品,我只是得到一个白色的 png 文件,上面什么都没有。还有什么我需要做的。我正在创建图像,但图像文件中没有任何内容。
    • 如果您执行以下操作会发生什么: plot(regCal); dev.copy(png,'filename.png') # 在目录中创建 .png 但其中没有任何内容 dev.off() # 这会插入图像,然后继续调用它直到到达“null device 1”
    【解决方案2】:

    我正在考虑将使用 googleVis 生成的 html 文件保存为 png,并在此处偶然发现了此线程。我能够使用webshot2::webshot() 解决我的问题。

    即您使用googleVis 创建一个html 文件,然后使用webshot2::webshot() 生成一个png。

    dat <- data.frame(From=c(rep("A",3), rep("B", 3)), 
                      To=c(rep(c("X", "Y", "Z"),2)), 
                      Weight=c(5,7,6,2,9,4))
    
    sk1 <- googleVis::gvisSankey(dat, from="From", to="To", weight="Weight")
    
    cat(sk1$html$chart, file = "Sankey.html") 
    
    webshot2::webshot(url = "Sankey.html",
                      file = "Sankey.png",
                      vheight = 400,
                      vwidth = 430,
                      zoom = 5)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-26
      • 1970-01-01
      相关资源
      最近更新 更多