ggiraph error when using coord_polar() and geom_segment_interactive

84 Views Asked by At

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.

In ggiraph I am using geom_segment_interactive as well as coord_polar(). Everything works fine until I add coord_polar().

Example of the issue using the ggiraph geom_segment_interative example.

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.

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(): ! Can't rename columns that don't exist. x Column x doesn't exist. Run rlang::last_error() to see where the error occurred.

If I change geom_segment_interactive to geom_segment and run the code, with and without coord_polar() it works. 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.

1

There are 1 best solutions below

0
On

That was a bug and it is fixed now in the latest github version (will be on cran soon).

Use devtools::install_github('davidgohel/ggiraph') to install it.

Please submit any issues you may encounter to https://github.com/davidgohel/ggiraph/issues