I am currently trying to manually resize the bubble map for Plotly. I managed to change the colors of the map using the provided data, but I cannot use the same logic to resize. To change colors, I just called: colors_wanted <- c("red", "blue", "black", "pink")and passed this command in colorsinternally plot_ly. What do you think, you can resize, and not use the formula in this case sqrt, to require dimensions?
library(plotly)
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_us_cities.csv')
df$hover <- paste(df$name, "Population", df$pop/1e6, " million")
df$q <- with(df, cut(pop, quantile(pop), include.lowest = T))
levels(df$q) <- paste(c("1st", "2nd", "3rd", "4th"), "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"))
plot_ly(df, lon = lon, lat = lat, text = hover,
marker = list(size = sqrt(pop/10000) + 1, line = list(width = 0)),
color = q, colors= colors_wanted, type = 'scattergeo', locationmode = 'USA-states') %>%
layout(title = '2014 US city populations<br>(Click legend to toggle)', geo= g)
source
share