See the source code and more examples here: https://github.com/plotly/knitr-demos
library(plotly)
## Loading required package: RCurl
## Loading required package: bitops
## Loading required package: RJSONIO
p = plotly("R-demos", "p9g4f35ytd")
# Load maps
library(maps)
## Warning: package 'maps' was built under R version 3.0.2
data(canada.cities)
# Create the hexagone map
trace1 <- list(x = map(regions = "canada", plot = FALSE)$x, y = map(regions = "canada",
plot = FALSE)$y)
# Create the plotable city data
trace2 <- list(x = canada.cities$long, y = canada.cities$lat, text = canada.cities$name,
type = "scatter", mode = "markers", marker = list(size = sqrt(canada.cities$pop/max(canada.cities$pop)) *
100, opacity = 0.5))
p$iplot(trace1, trace2, kwargs = list(filename = "canadian cities"))
p$embed("https://plot.ly/~ChrisP/9/600/600")