绘图地图悬停在';用R表示
使用from Plotly,地图悬停不会在RStudio(或使用RMarkdown编译的.html文件)中呈现:绘图地图悬停在';用R表示,r,plotly,R,Plotly,使用from Plotly,地图悬停不会在RStudio(或使用RMarkdown编译的.html文件)中呈现: library(plotly)#版本“4.7.1” df我认为这是由于您正在使用的plot\ly的更新版本(不再需要hoverinfo=“text”): 试试这个: library(plotly) # version ‘4.7.1’ df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/
library(plotly)#版本“4.7.1”
df我认为这是由于您正在使用的plot\ly的更新版本(不再需要hoverinfo=“text”):
试试这个:
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)) %>%
layout(title = '2014 US city populations<br>(Click legend to toggle)', geo = g) %>%
add_markers(x = ~lon, y = ~lat, size = ~pop, color = ~q, text = ~paste(df$name, "<br />", df$pop/1e6, " million")
)
p
library(plotly)#版本“4.7.1”
df我认为这是由于您正在使用的plot\ly的更新版本(不再需要hoverinfo=“text”):
试试这个:
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)) %>%
layout(title = '2014 US city populations<br>(Click legend to toggle)', geo = g) %>%
add_markers(x = ~lon, y = ~lat, size = ~pop, color = ~q, text = ~paste(df$name, "<br />", df$pop/1e6, " million")
)
p
library(plotly)#版本“4.7.1”
df这最近在开发版本devtools::install_github('ropensci/plotly')
这最近在开发版本devtools::install_github('ropensci/plotly')中得到了修复。