library(plotly)
df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv")
df$hover <- with(df, paste(state, '<br>', "Beef", beef, "Dairy", dairy, "<br>",
"Fruits", total.fruits, "Veggies", total.veggies,
"<br>", "Wheat", wheat, "Corn", corn))
# give state boundaries a white border
l <- list(color = toRGB("white"), width = 2)
# specify some map projection/options
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showlakes = TRUE,
lakecolor = toRGB('white')
)
p <- plot_geo(df, locationmode = 'USA-states') %>%
add_trace(
z = ~total.exports, text = ~hover, locations = ~code,
color = ~total.exports, colors = 'Purples'
) %>%
colorbar(title = "Millions USD") %>%
layout(
title = '2011 US Agriculture Exports by State<br>(Hover for breakdown)',
geo = g
)
p
上面的代码来自plotly website,产生的图应如下:
会发生什么?我是否需要安装其他软件包才能重现正确的情节?
答案 0 :(得分:2)
我也得到了这个。如果您打开javascript控制台,则会看到错误:
<li><a href="http://www.journeysofthecrew.com/p/adventures.html#SUP">Supai</a>
<ul>
<li><a href="#">Supai Walkthrough</a></li>
<li><a href="#">The Drive</a></li>
[ etc. ]
<li><a href="http://www.journeysofthecrew.com/p/adventures.html#CRV">Colorado River</a></li>
</ul>
</li>
正在尝试打开此文件:
li
这是一个截图:
我认为这是因为R-Studio的非专业版不支持 https 设计,因此除了将其包装为markdown并在浏览器中查看之外,可能无法解决我在下面描述。
如果您将其打包在R-markdown中(将您的代码放在以下行之间):
Failed to load resource: Unable to init SSL Context:
然后将其保存为 "https://cdn.plot.ly/world_110m.json"
文件)并编织它。然后它仍然无法在R-Studio预览浏览器中工作,但如果您使用&#34;在浏览器中打开&#34;功能并在Chrome中打开它(例如)。
或购买专业版:)。