Flat maps do not appear in R

I have successfully installed the plotly library for R.

To get started, I completed their getting started guide for R and directly copied the code from several graphs in my RStudio version 0.99.489.

Examples for scatter plots, field plots, etc. work well.

Examples for bubble and choropleth maps do not display correctly. Maps are not displayed at all. After running the code, only the title and legend are displayed.

Code References:

https://plot.ly/r/bubble-maps/

https://plot.ly/r/choropleth-maps/

Can anyone help?

Thanks in advance.

EDIT:

Instruments:

Dense library 2.016 for R

R Studio Version 0.99.489

R Version 3.2.2

Work in Windows 7 Home 64

One set of code tried to use the Plotly Bubble Map (copied directly from its user guides / code samples:

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) 

CHANGE No. 2

I highlighted the problem 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 am not sure how to fix the problem here or simplify the syntax to find out what might happen.

+6
source share
2 answers

I had similar problems with graphically displaying choropleth cards in RStudio Viewer. Even copying the code exactly as it was indicated in your links to a site with a stubborn site gave me only a name and a legend, but not a map.

However, when I expanded the Viewer with the "Show in new window" button, choropleth opens completely in my web browser.

This makes me think that the problem is this:

  • Something that is connected with the fact that the plot package itself does not work correctly in the RStudio environment (doubt it) or
  • This is only one of those cases where the plot is not displayed because the size of the Viewer window is too small. It happens to me if I run something like “pairs” in a large data frame with a lot of correlations. It does not appear in the viewer unless I expand it to a larger size or make it in the browser window.

I would like to know if there are any settings in RStudio or in the packages themselves that can fix this.

EDIT . I do not encounter this problem when rendering graphics on my laptop - just on the desktop. I believe that both versions work with the latest versions of R / RStudio, so I'm not sure why this is done and the other is not.

+7
source

You currently need an internet connection to view the scatter trace type - https://github.com/ropensci/plotly/issues/356

0
source

All Articles