简体   繁体   English

使用 coord_polar() 和 geom_segment_interactive 时出现 ggiraph 错误

[英]ggiraph error when using coord_polar() and geom_segment_interactive

I am working on making a circular graph of the occurrences of animals throughout the year.我正在制作一张全年动物发生率的圆形图。 where I have a number of variables (rings) and arrival and departure dates.我有许多变量(环)以及到达和离开日期。 I am trying to add more interactive functions to my graph with both shiny and ggiraph.我正在尝试使用 shiny 和 ggiraph 向我的图表添加更多交互功能。

In ggiraph I am using geom_segment_interactive as well as coord_polar().在 ggiraph 中,我使用 geom_segment_interactive 和 coord_polar()。 Everything works fine until I add coord_polar().在我添加 coord_polar() 之前一切正常。

Example of the issue using the ggiraph geom_segment_interative example.使用 ggiraph geom_segment_interative示例的问题示例。

dataset = data.frame(x=c(1,2,5,6,8),
y=c(3,6,2,8,7),
vx=c(1,1.5,0.8,0.5,1.3),
vy=c(0.2,1.3,1.7,0.8,1.4),
labs = paste0("Lab", 1:5))
dataset$clickjs = paste0("alert(\"",dataset$labs, "\")" )

gg_segment_2 = ggplot() +
  geom_segment_interactive(data=dataset, mapping=aes(x=x, y=y,
      xend=x+vx, yend=y+vy, tooltip = labs, onclick=clickjs ),
    arrow=grid::arrow(length = grid::unit(0.03, "npc")),
    size=2, color="blue") +
  geom_point(data=dataset, mapping=aes(x=x, y=y),
    size=4, shape=21, fill="white")

x <- girafe(ggobj = gg_segment_2)
if( interactive() ) print(x)

All of that works great.所有这些都很好。 If we add coord_polar() to the ggplot code it throws errors.如果我们将 coord_polar() 添加到 ggplot 代码中,它会引发错误。

gg_segment_2 = ggplot() +
  geom_segment_interactive(data=dataset, 
                           mapping=aes(x=x, y=y, xend=x+vx, yend=y+vy, tooltip = labs, onclick=clickjs ),
                           arrow=grid::arrow(length = grid::unit(0.03, "npc")),
                           size=2, color="blue") +
  geom_point(data=dataset, mapping=aes(x=x, y=y),
             size=4, shape=21, fill="white")+
  coord_polar()

x <- girafe(ggobj = gg_segment_2)
if( interactive() ) print(x)

Error in stop_subscript() : . stop_subscript()中的错误:。 Can't rename columns that don't exist.无法重命名不存在的列。 x Column x doesn't exist. x 列x不存在。 Run rlang::last_error() to see where the error occurred.运行rlang::last_error()以查看错误发生的位置。

If I change geom_segment_interactive to geom_segment and run the code, with and without coord_polar() it works.如果我将 geom_segment_interactive 更改为 geom_segment 并运行代码,无论有无 coord_polar() 它都可以工作。 Any suggestions of what I am missing would be greatly appreciated.任何关于我所缺少的建议将不胜感激。

I would like to be using the interactive version so when I use my real dataset in my shiny app I can select the different species to appear in the circular figure, but also be able to use the tooltip to identify the different species.我想使用交互式版本,所以当我在我的 shiny 应用程序中使用我的真实数据集时,我可以 select 不同的物种出现在圆形图中,而且还能够使用工具提示来识别不同的物种。

That was a bug and it is fixed now in the latest github version (will be on cran soon).这是一个错误,现在已在最新的 github 版本中修复(很快就会出现)。

Use devtools::install_github('davidgohel/ggiraph') to install it.使用devtools::install_github('davidgohel/ggiraph')安装它。

Please submit any issues you may encounter to https://github.com/davidgohel/ggiraph/issues请将您可能遇到的任何问题提交给https://github.com/davidgohel/ggiraph/issues

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM