【发布时间】:2019-08-22 21:29:58
【问题描述】:
我有这个ggplotly NBA 球场对象,显示了每个球员的投篮次数。如您所见,当我将鼠标悬停在球场的每个区域上时,我看到工具提示的行为非常不可预测。我喜欢它,因为球场是由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 交互)
【问题讨论】:
标签: r ggplot2 r-plotly ggplotly