我正试图复制在下面的悬停模式 这个 plotly的例子在33.1。
它只给你提供悬停中特定x坐标的信息,但有多个条目。
在我的真实数据集中,我没有设置任何额外的美工,除了 text
因为我想在悬停中得到一些额外的信息。我的数据集对一些X坐标有多个条目,就像例子中的那样。然而,当我尝试为我的真实数据集调整代码时,我的数据集中的特定x坐标的悬停现在只显示一个人。
p <- ggplot(df, mapping = aes(x, Points, text = paste("Person: ", Person,
"\nEvent: ", Event))) +
# geom_jitter(shape = 4, width = 0, height = 50) +
geom_point(shape = 4) +
ggplotly(p) %>%
layout(hovermode = "x")
悬停一个特定的X坐标,现在只显示一个人。我试过在垂直方向上抖动点,看看是否会有不同,因为我读到重叠点经常会有问题,但这并不能解决我的问题。
我试着设置了一个颜色美学,只是为了测试一下会是什么样子。
p <- ggplot(df, mapping = aes(x, Points, colour = Event, text = paste("Person: ", Person,
"\nEvent: ", Event))) +
geom_point(shape = 4)
ggplotly(p) %>%
layout(hovermode = "x")
我可以很容易地去掉图例,让所有的颜色都设置为一种颜色,但在悬停中,它显示的是多个x坐标的值,这又带来了另一个问题。
希望的输出 在X坐标1090处。
我的DF:
df <- structure(list(Event = c("2012", "2008", "2005", "2012", "2018", "2005", "2009", "2018", "2013", "2016", "2007", "2000", "2017", "2000", "2000", "2015", "2004", "2012", "2002", "2015", "2017", "2016", "2018", "2013", "2005", "2015", "2001", "2000", "2008", "2004", "2012", "2003", "2016", "2015", "2007", "2009", "2006", "2011", "2016", "2001", "2018", "2010", "2011", "2016", "2005", "2017", "2004", "2004", "2009", "2004", "2015", "2002", "2012", "2001", "2006", "2004", "2014", "2012", "2003", "2008", "2007", "2015", "2009", "2011"), x = c(1106, 1124, 1090, 1110, 1090, 1107, 1066, 1112, 1098, 1096, 1121, 1121, 1094, 1121, 1131, 1105, 1106, 1109, 1083, 1097, 1093, 1062, 1082, 1105, 1067, 1122, 1099, 1075, 1113, 1108, 1090, 1072, 1130, 1127, 1086, 1089, 1114, 1111, 1117, 1072, 1129, 1135, 1128, 1086, 1081, 1126, 1086, 1050, 1093, 1055, 1126, 1089, 1035, 1074, 1083, 1066, 1050, 1078, 1075, 1115, 1104, 1093, 1088, 1125), Points = c(847, 808, 883, 838, 883, 845, 938, 834, 865, 870, 814, 814, 874, 814, 793, 850, 847, 841, 899, 867, 876, 947, 901, 850, 935, 812, 863, 917, 832, 843, 883, 924, 795, 801, 892, 885, 830, 836, 823, 924, 797, 784, 799, 892, 903, 804, 892, 975, 876, 963, 804, 885, 1011, 919, 899, 938, 975, 910, 917, 827, 852, 876, 888, 806), Person = c("Pascal", "Hans", "Attila", "Brent", "Fredrik", "Óscar", "Yunior", "Pieter", "Sergey", "Adam", "Nicklas", "Fedor", "Marek", "Michael", "Indrek", "Simone", "Qi", "Willem", "Eugenio", "Pieter", "Devon", "Kai", "Martin", "Adam", "Hamdi", "Bastien", "Eduard", "Lev", "Aleksey", "Indrek", "Norman", "Dmitriy", "Keisuke", "Keisuke", "Andrei", "Eelco", "Andrei", "Kim", "Jonas", "Dean", "Niklas", "Petter", "Mikk", "Cedric", "Christopher", "Gael", "Markus", "Dmitriy", "Norman", "Nikolay", "Pau", "Thomas", "Ashton", "Lev", "Maurice", "Chiel", "Trey", "Sergey", "Markus", "Mikk", "Roman", "Ingmar", "Pascal", "Roman")), row.names = c(NA, -64L), class = "data.frame")