Is there a way to keep a piechart subplot from changing its domain with Plotly in R using crosstalk?
The idea here is to have a choropleth map on the left side and a piechart on the right side. When I click on one country on the map, the piechart shows data from that country. I use a SharedData object and the link between both subplots works fine.
The problem is: The piechart subplot stays where it should for the first location Code in my dataframe (AUS in this case), but when I click on another country, the piechart moves to the center of the plot.
Maybe this is a bug or it's not implemented yet?
Here is my code:
library(plotly)
library(crosstalk)
df <- data.frame(Code = rep(c("AUS", "BRA", "CAN", "USA"),each = 4),
Category = rep(c("A","B","C","D"),4),
Values = rep(c(10,15,5,20),each=4),
Perc = c(10, 20, 20, 50,
35, 5, 15, 45,
5, 75, 5, 15,
60, 30, 10, 0))
shared_data <- SharedData$new(df, key = ~Code)
p1 <- shared_data %>%
plot_geo(z = ~Values,
zmin=0,
zmax=20,
color = ~Values,
locations = ~Code,
visible=T)
p2 <- shared_data %>%
plot_ly(type = "pie",
visible = T,
showlegend = F,
values = ~Perc,
labels = ~Category,
domain = list(x = c(0.5, 1),
y = c(0,1)),
hole = 0.8,
sort = F) %>%
layout(autosize = T, geo = list(domain = list(x = c(0.5, 1),
y = c(0,1)
))
)
sp1 <- subplot(p1, p2) %>%
hide_legend() %>%
hide_colorbar() %>%
layout(xaxis = list(domain=c(0,0.5)), #adding this does not work either
xaxis2 = list(domain=c(0.5,1)))