http://blog.revolutionanalytics.com/2015/09/using-r-with-jupyter-notebooks.html http://blog.revolutionanalytics.com/2016/01/pipelining-r-python.html
conda install -c r ipython-notebook r-irkernel conda install rpy2
%load_ext rpy2.ipython
%%R -o diamonds
#install.packages("ggplot2")
library("ggplot2")
data(diamonds)
head(diamonds)
ggplot(diamonds, aes(x= carat, y= price, color= cut)) +
geom_point(alpha=0.5)
from bokeh.plotting import figure, output_file, show
from rpy2.robjects import pandas2ri
from bokeh.palettes import brewer
import pandas
import bokeh
df = pandas2ri.ri2py_dataframe(diamonds)
print(type(df))
#print(df)
# brute through colors
# look at https://github.com/bokeh/bokeh/issues/5112 for a better way
cuts = list(set(df['cut']))
print(cuts)
colors = brewer["Spectral"][len(cuts)]
# print(colors)
map = { cuts[i]:colors[i] for i in range(len(cuts)) }
print(map)
cutcode = [ map[ci] for ci in df['cut'] ]
# print(cutcode)
bokeh.io.output_notebook() # inline output
# create a new plot with a title and axis labels
p = figure(title="simple plot example", x_axis_label='carat', y_axis_label='price')
# add a circle renderer
p.circle(x=df['carat'], y=df['price'], color=cutcode, size=5, alpha=0.5)
# show the results
show(p)