ggplotly工具提示反应不稳定

问题描述 投票:0回答:1

enter image description here

我有这个NBA球场的ggplotly对象,展示了每个球员的投篮尝试。正如您所看到的,当我将鼠标悬停在球场的每个区域上时,我发现工具提示的表现非常不可预测。我觉得它是因为法院是用geom_polygongeom_path制作的。请参阅下面的代码:

数据(gg_lineup_fga):http://www.filedropper.com/gglineupfga

rank_colors <- RColorBrewer::brewer.pal(5, "RdYlBu")

ggplot2::ggplot(data = gg_lineup_fga, ggplot2::aes(x=long, 
                                                                y=lat, 
                                                                group = group,
                                                                fill = rank,
                                                                text = paste0("FGA : ", round(fga, 2)))) +
  ggplot2::facet_grid(. ~ player) +
  ggplot2::geom_polygon()  +
  ggplot2::geom_path(color = "black")  +
  ggplot2::coord_equal() +
  ggplot2::scale_fill_manual(values = rank_colors,
                             limits = 1:5,
                             name = NULL) +
  ggplot2::theme(axis.line=ggplot2::element_blank(),
                 axis.text.x=ggplot2::element_blank(),
                 axis.text.y=ggplot2::element_blank(),
                 axis.ticks=ggplot2::element_blank(),
                 axis.title.x=ggplot2::element_blank(),
                 axis.title.y=ggplot2::element_blank(),
                 panel.background=ggplot2::element_blank(),
                 panel.border=ggplot2::element_blank(),
                 panel.grid.major=ggplot2::element_blank(),
                 panel.grid.minor=ggplot2::element_blank(),
                 strip.text = ggplot2::element_text(size = 16), 
                 strip.background = ggplot2::element_blank(),
                 legend.position = "none",
                 # legend.margin = ggplot2::margin(0.1, 0.1, 0.1, 0, "npc"),
                 plot.margin = ggplot2::unit(c(0, 0, 0, 0), "cm"),
                 panel.spacing.y = ggplot2::unit(0, "cm"),
                 text=element_text(size=16, family="Avenir"))

为了解决这个问题,我可以拿出geom_path,但这会消除法院区域的黑线边界。我想知道是否在plotly中有一个参数阻止工具提示与geom_path交互(仅与geom_polygon交互)

r ggplot2 r-plotly ggplotly
1个回答
0
投票

删除geom_path并添加颜色到geom_polygon颜色边界,即,geom_polygon(color ='black')

© www.soinside.com 2019 - 2024. All rights reserved.