I have successfully installed the plotly library for R.
To get started, I followed their Getting Started for R guide and directly copied the code from several plots in my RStudio Version 0.99.489.
The examples for scatterplots, box plots, etc. work well.
The examples for bubble and choropleth maps do not plot properly. The maps do not render at all. Only title and legend show after running the code.
Links to the code are here:
https://plot.ly/r/bubble-maps/
https://plot.ly/r/choropleth-maps/
Can anyone help?
Thanks in advance.
EDIT:
Tools:
Plotly Library 2.016 for R
R Studio Version 0.99.489
R Version 3.2.2
Running on Windows 7 Home 64
One set of code tried for a Plotly Bubble Map (copied straight from their user guide/code examples:
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)))
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")
)
plot_ly(df, lon = lon, lat = lat, text = hover,
marker = list(size = sqrt(pop/10000) + 1),
color = q, type = 'scattergeo', locationmode = 'USA-states') %>%
layout(title = '2014 US city populations<br>(Click legend to toggle)', geo = g)
EDIT #2
I've isolate the issue to here:
plot_ly(df, lon = lon, lat = lat, text = hover,
marker = list(size = sqrt(pop/10000) + 1),
color = q, type = 'scattergeo', locationmode = 'USA-states')
I'm not sure how to troubleshoot from here or simplify the syntax to see what might be happening.
I have had similar troubles with plotly rendering choropleth maps in the RStudio Viewer. Even copying the code exactly as provided in your links to the ployly website gave me just a title and legend, but no map.
However, when I expanded the Viewer using the "Show in new window" button, the choropleth opens up in my web brower fully rendered.
This leads me to believe that the issue is either:
I would like to know if there are any settings either in RStudio or in the packages themselves that may fix this.
EDIT: I do not encounter this issue when rendering the plot on my laptop -- just my desktop. I believe both are running the latest R/RStudio versions so I'm not sure why one renders and one does not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With