suppressMessages(library(devtools))
suppressMessages(install_github("ropensci/plotly"))
suppressMessages(library(ggplot2))
suppressMessages(library(plyr))
suppressMessages(library(plotly))
py <- plotly(username="r_user_guide", key="mw5isa4yqp") # open plotly connection
# grab data from Tableau
df <- read.csv("http://public.tableausoftware.com/views/WomenManagers/WomanPower.csv")
# verify, show first 5 rows
df[1:5,]
Country Latitude..generated. Longitude..generated. X..of.women.managers 1 Albania 40.6540 20.076 22.5% 2 Algeria 28.6045 2.640 4.9% 3 Argentina -33.1660 -64.310 31.0% 4 Aruba 12.5560 -70.024 41.0% 5 Australia -24.5780 133.582 36.2%
ggplot(df, aes(x=Latitude..generated.)) + geom_histogram()
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
suppressMessages(py$ggplotly(session="notebook")) # send to plotly, embed in Notebook
plotly_iframe <- function(url) {
# set width and height from options or default square
w <- "600"
h <- "600"
html <- paste("<iframe height=\"", h, "\" id=\"igraph\" scrolling=\"no\", seamless=\"seamless\"\n\t\t\t\tsrc=\"",
url, "\" width=\"", w, "\" frameBorder=\"0\"></iframe>", sep = "")
return(html)
}
display_html( plotly_iframe("https://plot.ly/~MattSundquist/8740")) # edit in GUI, embed
# CSS styling within IPython notebook
display_html(getURL("https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css"))