[英]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.