我已成功为R安装了plotly库.
首先,我按照他们的R入门指南,直接从我的RStudio版本0.99.489中的几个图中复制了代码.
散点图,箱形图等的示例效果很好.
气泡和等值线图的示例没有正确绘制.地图根本不渲染.运行代码后只显示标题和图例.
代码链接如下:
https://plot.ly/r/bubble-maps/
https://plot.ly/r/choropleth-maps/
有人可以帮忙吗?
提前致谢.
编辑:
工具:
Rlot的Plotly Library 2.016
R Studio版本0.99.489
R版本3.2.2
在Windows 7 Home 64上运行
为Plotly Bubble Map尝试了一组代码(直接从他们的用户指南/代码示例复制:
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)
Run Code Online (Sandbox Code Playgroud)
编辑#2
我把问题隔离到了这里:
plot_ly(df, lon = lon, lat = lat, text = hover,
marker = list(size = sqrt(pop/10000) + 1),
color = q, type = 'scattergeo', locationmode = 'USA-states')
Run Code Online (Sandbox Code Playgroud)
我不确定如何从此处进行故障排除或简化语法以查看可能发生的情况.
我在RStudio Viewer中用图形渲染等值区域图有类似的麻烦.即使完全按照链接中提供的代码复制到ployly网站,也只给了我一个标题和图例,但没有地图.
但是,当我使用"在新窗口中显示"按钮展开查看器时,在我的网络浏览器中完全渲染了等值线.
这让我相信问题是:
我想知道在RStudio或包本身中是否有任何设置可以解决这个问题.
编辑:我在笔记本电脑上渲染绘图时没有遇到这个问题 - 只是我的桌面.我相信两者都运行最新的R/RStudio版本所以我不确定为什么一个渲染而一个不渲染.