难以理解自定义geom的ggplotly界面

时间:2017-09-07 14:21:35

标签: r ggplot2 ggplotly

我已经取得了一些成功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)

ggalt

显然GeomLine并不正确 - 对于这个扩展来说,GeomPoint似乎更自然一点 - 但它可能只是我无法减少它而我需要实现geom2trace。但是,对于任何一种方法需要进出的内容我都不太了解。有人可以帮忙吗?是否有其他实现Plotly接口的ggplot2扩展示例?

编辑:我看过enter image description here,但我不确定我能在这里走多远。我有点希望我可以用GeomPoint点代替自定义grobs,就像使用grid一样,但看起来Plotly API只需要基本的点属性。

0 个答案:

没有答案