我正在使用悬停工具提示来绘制美国的地图,而我已经做了一些工作。但是,我希望在工具提示中显示的每个变量的每个状态都有多个观察值,并且当前仅显示每个状态的第一个观察值。每个观察结果都是1976年总统选举在某个州的表现,我希望悬停工具提示显示该州每个候选人的表现,而不仅仅是该州列出的第一位候选人。
这是我目前正在使用的代码。
候选人代表候选人的姓名,state_share和round_share代表候选人分别获得的州民众投票和州选举人选的百分比。
library(plotly)
colorscale <- c("blue" , "purple" , "red")
l <- list(color = toRGB("white"), width = 2)
# specify some map projection/options
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showlakes = FALSE
)
threshold10$hover <- with(threshold10, paste(state, "<br>" , canvec ,':',
state_share ,",","Electoral Votes", round_share ))
fig <- plot_geo(subset(threshold10, year == 1976), locationmode = 'USA-states')
fig <- fig %>%
add_trace(
z = ~evotes, text = ~ hover , locations = ~state_po,
color = ~state_share , colors = colorscale) %>%
layout(title = '1976 Electoral Vote Allocation <br> 10% State Threshold',
geo = g)
fig
我还将附加数据集的图像和由我的代码生成的地图。感谢任何人提供的帮助。我刚开始使用绘图和贴图,所以如果这是一个简单的问题,对此感到抱歉。谢谢您的帮助。