
我有这个NBA球场的ggplotly对象,显示了每个球员的投篮次数。正如你所看到的,当我将鼠标悬停在球场的每个区域上时,我看到工具提示的行为非常不可预测。我感觉是这样的,因为法庭是用geom_polygon和geom_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交互)
发布于 2019-04-02 03:10:51
移除geom_path并将颜色添加到geom_polygon以对边界进行着色,即geom_polygon(color ='black')
https://stackoverflow.com/questions/55459802
复制相似问题