Plotting with Tableau,
R, & Plotly

In [1]:
suppressMessages(library(devtools))
suppressMessages(install_github("ropensci/plotly"))
suppressMessages(library(ggplot2))
suppressMessages(library(plyr))
In [2]:
suppressMessages(library(plotly)) 
In [3]:
py <- plotly(username="r_user_guide", key="mw5isa4yqp")  # open plotly connection
In [4]:
# grab data from Tableau
df <- read.csv("http://public.tableausoftware.com/views/WomenManagers/WomanPower.csv")
In [5]:
# verify, show first 5 rows
df[1:5,]
Out[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%
In [6]:
ggplot(df, aes(x=Latitude..generated.)) + geom_histogram()
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
Out[6]:

In [7]:
suppressMessages(py$ggplotly(session="notebook"))  # send to plotly, embed in Notebook
In [8]:
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)
}
In [9]:
display_html( plotly_iframe("https://plot.ly/~MattSundquist/8740"))  # edit in GUI, embed
In [10]:
# CSS styling within IPython notebook
display_html(getURL("https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css"))