簡體   English   中英

密謀hoverinfo將無法在R中工作

[英]Plotly hoverinfo wont work in R

因此,我在制作氣泡圖時從R的plotly復制了示例。 我目前可以制作氣泡圖,但是無法使hoverinfo正常工作。 我在其他帖子上看到hoverinfo給其他人帶來了問題,但是我發現的任何修復方法都無法使我的工作正常。 我在下面提供了少量的數據。

誰能密謀知道我是否犯了一個我沒有看到的小錯誤?

數據

All_Time_Backers_city <- c(871,25,478,25,14,193)
Latitude <- c(32.44861,42.10472,42.48500,34.06583,34.77444,41.93167)
Longitude <- c(-99.73278,-70.94583,-71.43333,-84.67694,-96.67806,-87.98889)
City <- c("Abilene","Abington","Acton","Acworth","Ada","Addison")
z <- data.frame(All_Time_Backers_city, Latitude, Longitude, City)

library(plotly)
z$q <- with(z, cut(All_Time_Backers_city, quantile(All_Time_Backers_city)))
levels(z$q) <- paste(c("1st", "2nd", "3rd", "4th", "5th"), "Quantile")
z$q <- as.ordered(z$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(z, locationmode = 'USA-states', sizes = c(5, 250)) %>%
   add_markers(
     x = ~Longitude, y = ~Latitude, size = ~All_Time_Backers_city, color = 
~q,
     text = ~paste(City, "<br />", All_Time_Backers_city, "Backers"), 
hoverinfo = "text+x+y"
    )%>%
   layout(title = 'Backers City All Time', geo = g)
p

我發現彈出框有什么問題。 我有一些在加拿大的數據點,還有一些在墨西哥的數據點。 我用於繪圖的地圖僅是美國地圖,我仍然在地圖外繪制點,但是當鼠標懸停在上方時,框沒有彈出。 我不得不換成北美大小的地圖。

碼:

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

g <- list(
  scope = 'north america',
  showland = TRUE,
  landcolor = toRGB("grey83"),
  subunitcolor = toRGB("white"),
  countrycolor = toRGB("white"),
  showlakes = TRUE,
  lakecolor = toRGB("white"),
  showsubunits = TRUE,
  showcountries = TRUE,
  resolution = 50,
  projection = list(
    type = 'conic conformal',
    rotation = list(lon = -100)
  ),
  lonaxis = list(
    showgrid = TRUE,
    gridwidth = 0.5,
    range = c(-140, -55),
    dtick = 5
  ),
  lataxis = list(
    showgrid = TRUE,
    gridwidth = 0.5,
    range = c(15, 70),
    dtick = 5
  )
)

p <- plot_geo(z, sizes = c(5, 250))%>%
  add_markers(x = ~Longitude, y = ~Latitude,
      size = ~All_Time_Backers_city, 
     color = ~q, text = ~paste(z$City, "<br />", z$All_Time_Backers_city, 
"Backers")
   )%>%
  add_trace(
    z = ~Mapping$`Mean Campaign USD`, text = ~Mapping$hover, locations = 
~Mapping$code
  ,locationmode="USA-states")%>%
   layout(title = 'Backers City All Time', geo = g)
p 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM