简体   繁体   English

导出svg格式的图,是一个`girafe` object(`ggiraph`包)

[英]Exporting a graph in svg format, which is a `girafe` object (`ggiraph` package)

ggiraph package is suitable for generating interactive graphics. ggiraph package 适用于生成交互式图形。

I was trying to execute some examples found online concerning package ggiraph and I was not able to find anywhere how to export the interactive graph generated, maybe in format svg (or other).我试图执行一些在网上找到的关于 package ggiraph的例子,但我无法在任何地方找到如何导出生成的交互式图形,格式可能是 svg(或其他)。

Below the code:代码下方:

library(ggplot2)
library(ggiraph)
library(patchwork)
library(cowplot)

mtcars <- mtcars
mtcars$tooltip <- rownames(mtcars)

gg1 <- ggplot(mtcars) +
  geom_point_interactive(aes(x = drat, y = wt, color = qsec, 
    tooltip = tooltip, data_id = tooltip ), size = 4) 

gg2 <- ggplot(mtcars) +
  geom_point_interactive(aes(x = qsec, y = disp, color = mpg, 
    tooltip = tooltip, data_id = tooltip ), size = 4)

Then I tried to export it:然后我尝试导出它:

oggetto <- girafe( ggobj = plot_grid(gg1, gg2), width_svg = 8, height_svg = 4)
library(svglite)
ggsave(file="test.svg", plot=oggetto, width=10, height=8)

getting the following error:出现以下错误:

Error in UseMethod("grid.draw") : 
  no applicable method for 'grid.draw' applied to an object of class "c('girafe', 'htmlwidget')"

Does somebody knows how to export the images?有人知道如何导出图像吗?

Thank you in advance for every eventual reply!预先感谢您的每一个最终回复! Giacomo贾科莫

You can save the interactive plot containing the svg in a HTML file using htmltools::save_html(oggetto, "out.html")您可以使用htmltools::save_html(oggetto, "out.html")将包含 svg 的交互式 plot 保存在 HTML 文件中

out.html contains JavaScript eg ggiraphjs.min.js required to run the interactivity. out.html包含 JavaScript,例如运行交互所需的ggiraphjs.min.js Plain SVG files can display tooltips using the title attribute, but the orange point color on hover on both plots simultaneously seems to require JavaScript.普通 SVG 文件可以使用 title 属性显示工具提示,但两个图上 hover 上的橙色点颜色同时似乎需要 JavaScript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与 flexdashboard 一起使用后,ggiraph::girafe() output 的大小与 RStudio 查看器上的文档不一致 - Sizing of ggiraph::girafe() output is not consistent with documentation on RStudio viewer after use with flexdashboard 为 ggiraph 的交互式工具提示格式化表格的最简单方法 - Easiest way to format table for interactive tooltip for ggiraph 更改包元数据林图中的置信区间格式? - Change confidence interval format in package metafor forest graph? 使用 xlsx package 从 r 导出到 excel 时如何格式化千位分隔符? - How to format thousands separator when exporting from r to excel using xlsx package? 我正在尝试使用 ggiraph 将交互性添加到 ggplot2 图中,它不起作用 - I am trying to use ggiraph to add interactivity to a ggplot2 graph, it's not working 将非日期格式的输出格式化为日期对象 - formatting the output which is not in a date format to a date object 在R中以原始格式导出数据 - Exporting data in raw format in R 将ggplot对象转换为使用Open Sans Semibold字体的svg - convert ggplot object into svg which use Open Sans Semibold font 从R包导出环境 - Exporting an environment from an R package rcpp 函数未在 r package 中导出 - rcpp functions not exporting in r package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM