Plotly地图悬停不会在R中渲染

时间:2017-11-06 17:35:26

标签: r plotly

使用Plotly中的example code,地图悬停在RStudio(或使用RMarkdown编译的.html文件)中渲染:

library(plotly) # version ‘4.7.1’
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_us_cities.csv')

df$q <- with(df, cut(pop, quantile(pop)))
levels(df$q) <- paste(c("1st", "2nd", "3rd", "4th", "5th"), "Quantile")
df$q <- as.ordered(df$q)

g <- list(
  scope = 'usa',
  projection = list(type = 'albers usa'),
  showland = TRUE,
  landcolor = toRGB("gray85"),
  subunitwidth = 1,
  countrywidth = 1,
  subunitcolor = toRGB("white"),
  countrycolor = toRGB("white")
)

p <- plot_geo(df, locationmode = 'USA-states', sizes = c(1, 250)) %>%
  add_markers(
    x = ~lon, y = ~lat, size = ~pop, color = ~q, hoverinfo = "text",
    text = ~paste(df$name, "<br />", df$pop/1e6, " million")
  ) %>%
  layout(title = '2014 US city populations<br>(Click legend to toggle)', geo = g)

p

我还试过hovertext代替text但没有取得任何成功。

2 个答案:

答案 0 :(得分:1)

我认为这是由于您正在使用的更新版本的plot_ly(不再需要hoverinfo =“text”): 试试这个:

select * from table where channel = 4 OR channel = 5 order by time desc limit 10

它适用于我的RStudio。

答案 1 :(得分:0)

最近在开发版devtools::install_github('ropensci/plotly')

中修复了此问题