我已经取得了一些成功extending ggflags
to use SVGs,现在我正试图让这个扩展程序与ggplotly()
一起使用。 Plotly文档has a nice section on translating custom geoms,它主要归结为为您的geom或to_basic
方法提供geom2trace
方法。
我说实话:我在这里超出了我的深度,而且我试图根据两个命名的例子拼凑一些东西:ggmosaic
和{{3} }。但是很简单:
#' @name plotly_helpers
#' @title Plotly helpers
#' @description Helper functions to make it easier to automatically create plotly charts
#' @importFrom plotly to_basic
#' @export
to_basic.GeomFlag <- getFromNamespace("to_basic.GeomPoint", asNamespace("plotly"))
运行devtools::document()
时给我一个错误:
object 'to_basic.GeomPoint' not found
如果我将它更改为GeomLine包文档并安装,但是一个简单的图表显示如下:
df = data_frame(
f = rep(1:5, each = 4),
x = rep(1:4, times = 5),
y = c(1:2, 2:1, 2:1, 1:2, 1:2, 2:1, 2:1, 1:2, 2:1, 1:2),
s = c(1:4, 4:1, 1:4, 4:1, 1:4),
c = rep(c('au', 'us', 'gb', 'de'), 5))
p1 = ggplot(df) + geom_flag(aes(x = x, y = y, size = s, frame = f, country = c)) + scale_country()
ggplotly(p1)
显然GeomLine并不正确 - 对于这个扩展来说,GeomPoint似乎更自然一点 - 但它可能只是我无法减少它而我需要实现geom2trace
。但是,对于任何一种方法需要进出的内容我都不太了解。有人可以帮忙吗?是否有其他实现Plotly接口的ggplot2
扩展示例?
编辑:我看过,但我不确定我能在这里走多远。我有点希望我可以用GeomPoint点代替自定义grobs,就像使用
grid
一样,但看起来Plotly API只需要基本的点属性。