2

I just can't get plot_geo to display correctly.
This is weird, because I can use other plotly commands, including ggplotly, to create interactive plots. I am running R version 3.3.3 and RStudio version 1.1.350 with plotly version 4.7.1. Initially, I call on 3 packages by recommendation I saw here: plot-geo-returning-a-blank-map-in-r

library(dplyr)
library(ggplot2)
library(plotly)
map_data("world", "canada") %>%
  group_by(group) %>%
  plot_geo(x = ~long, y = ~lat) %>%
  add_markers(size = I(1))

plot_image

I get an empty plot, but if I hover over it, I can see the latitude and longitude information.

Map data in ggplot2 works to seem fine as I can run this example without a problem:

if (require("maps")) {
states <- map_data("state")
arrests <- USArrests
names(arrests) <- tolower(names(arrests))
arrests$region <- tolower(rownames(USArrests))

choro <- merge(states, arrests, sort = FALSE, by = "region")
choro <- choro[order(choro$order), ]
ggplot(choro, aes(long, lat)) +
  geom_polygon(aes(group = group, fill = assault)) +
  coord_map("albers",  at0 = 45.5, lat1 = 29.5)

ggplot(choro, aes(long, lat)) +
  geom_polygon(aes(group = group, fill = assault / murder)) +
  coord_map("albers",  at0 = 45.5, lat1 = 29.5)
}

Would anyone know how to debug this problem? I've tried to reinstall ggplot2 and plotly from both CRAN and GitHub without much luck.

creativename
  • 398
  • 2
  • 15
  • 1
    Referencing the answer here: https://stackoverflow.com/a/36558618/8449629 Choosing the "Show in new window" option in RStudio's plot pane worked for me. Maybe plotly just doesn't play well with RStudio. – Z.Lin Sep 01 '17 at 03:48
  • @Z.Lin You're right! Opening it in a new window works for me as well. The weird thing is I can run the same code under the same exact conditions on my other laptop and it would generate the results in RStudio Viewer. I don't want to open up a new tab each time, so I would love to know why this issue occurs and how it can be fixed if possible. – creativename Sep 01 '17 at 03:51
  • It's listed as a closed issue on plotly's Github page [here](https://github.com/ropensci/plotly/issues/717). Last reply from the developers back in Mar is that the dev version should fix it. Haven't tested that myself as I don't really use plotly for my work. – Z.Lin Sep 01 '17 at 08:19
  • 1
    I asked plotly developers directly, and I was told that it was an RStudio issue that they could not fix. This is weird because my colleague seems to have no issues (we have same R/RStudio/ggplot2/plotly versions).. either way, thanks for your help! – creativename Sep 05 '17 at 19:18
  • I have the same issue. Plotly issue 356 ( https://github.com/ropensci/plotly/issues/356) mentions that an Internet connection is required. I wonder if it is something to do with a firewall. For example to download packages from GitHub I need to use httr package, as per https://stackoverflow.com/questions/17783686/solution-how-to-install-github-when-there-is-a-proxy. – user1420372 Jan 09 '18 at 01:35

0 Answers0