使用r-plotly在热图中的相应美国州显示注释

时间:2019-01-11 11:19:01

标签: plotly r-plotly

我正在尝试在R中使用plotly创建热图,并且被困在图表中相应状态的注释上。

我可以使用悬停选项,将鼠标光标移至特定状态并查看自己的值。当我必须将地图导出为png时,其中不显示与状态相对应的值时,就会出现问题。

 library(plotly)


df <- read.csv("50_us_state_names.csv")
df$hover <- with(df, paste(state, '<br>', "Weights", lbs))
l  <- list(color = toRGB("white"), width = 2)
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showlakes = TRUE,
lakecolor = toRGB('white')
)
p <- plot_geo(df, locationmode = 'USA-states') %>%
add_trace(
z = ~total.exports, text = ~hover, locations = ~code,
color = ~total.exports, colors = 'YlOrRd'
 ) %>%
 colorbar(title = "Weight in lbs") %>%
 layout(
 title = 'Weight wide breakdown<br>(Hover for breakdown)',
 geo = g
 ) 

 p     

我需要在地图上显示相应州的值total.exports

0 个答案:

没有答案