Skip to content

Instantly share code, notes, and snippets.

@benjaminchodroff
Last active February 21, 2017 22:25
Show Gist options
  • Save benjaminchodroff/20693df79894f036b1c238039cd9afb4 to your computer and use it in GitHub Desktop.
Save benjaminchodroff/20693df79894f036b1c238039cd9afb4 to your computer and use it in GitHub Desktop.
import rpy2.robjects.lib.ggplot2 as ggplot2
import rpy2.robjects as ro
from rpy2.robjects.packages import importr
from rpy2.robjects import pandas2ri
pandas2ri.activate()
predprice = pd.DataFrame({"Predicted": [x for x in pred], "Actual": [y for y in price], "Color": [z for z in color], "Clarity": [x for x in clarity]})
yourdiamond = pd.DataFrame({"Predicted": [ypred],"Actual": [ypri]})
ro.globalenv['dataframe'] = predprice
pp = ggplot2.ggplot(predprice)
pp += ggplot2.aes_string(x='Predicted', y='Actual')
pp += ggplot2.geom_point(ggplot2.aes_string(color='factor(Color, labels = c("D","E", "F", "G", "H","I","J","K"))'))
pp += ggplot2.geom_point(data=yourdiamond,color="red",shape="X",size=5)
pp += ggplot2.geom_abline(intercept=ablinecoef[0],slope=ablinecoef[1],color="darkgreen",linetype="dashed")
pp += ggplot2.ggtitle("Actual vs Predicted Price for Diamonds",subtitle="Based on Pricescope.com Data")
pp += ggplot2.labs(color="Color")
caption = formula+'\n'+ars+'\n'+"Sample Size = " + str(len(price))+" Diamonds"+'\n'+Sdiam+'\n'+Spred+'\n'+Sdiff+'\n'+Ssavings
pp += ggplot2.labs(caption=caption)
pp += ggplot2.scale_colour_brewer(palette = "PiYG")
pp.save("output.png")
Image(filename='output.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment