连接到 R ggiraph 中数据的交互式图例

问题描述

我想创建一个地图,当我单击图例时,该地图会突出显示具有填充值的区域。也就是说,如果我在图例上单击 0.75,具有该值的状态将亮起。我猜有一种方法可以在 ggiraph 中使用 scale_fill_interactive 但不太确定。到目前为止,这是我的代码

library(ggplot2)
library(ggmap)
library(maps)
library(mapdata)
library(ggiraph)

states <- map_data("state")

y<-runif(15537,min = 0,max = 1)
states$coverage <-y


ggplot(data = states) + 
  geom_polygon(aes(x = long,y = lat,fill = coverage,group = group),color = "white") + 
  coord_fixed(1.3) +
  guides(fill=FALSE)


g <- ggplot(states) +
  geom_polygon_interactive(
    color='grey',aes(long,lat,group=group,fill=coverage,tooltip=region)) +
  labs(title='Case Management in Children (CM) under the age of five',subtitle='Business as Usual Scenario',caption='The Demographic and Health surveys was used to parameterize CM coverage',fill = "")+ 
  theme(axis.text.x = element_blank(),axis.text.y = element_blank(),axis.ticks = element_blank(),rect = element_blank(),plot.title = element_text(face="bold"),plot.subtitle = element_text(face ="italic"),plot.caption = element_text(size = 8,face = "italic"))+
  xlab("")+
  ylab("")

gg<- g + scale_fill_viridis_c_interactive(tooltip = states$region)

widgetframe::frameWidget(ggiraph(code=print(gg)))

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)