Skip to content

Instantly share code, notes, and snippets.

@msund
Created May 28, 2014 07:41
Show Gist options
  • Save msund/84bc2cd7681ef8324687 to your computer and use it in GitHub Desktop.
Save msund/84bc2cd7681ef8324687 to your computer and use it in GitHub Desktop.
{
"metadata": {
"name": "",
"signature": "sha256:0066d7751e4802e747a189c766f68718da3fe272e314ebd5e4c27d43535c1cf9"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Dataverse example plots"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"These were drawn from two datasets.\"[Replication data for: Asset Prices, Consumption, and the Business Cycle](http://thedata.harvard.edu/dvn/faces/study/StudyPage.xhtml;jsessionid=d814bb72587b5ac4c99920b4332a?globalId=hdl:1902.1/KSCWRAGNIJ)\" and \"[Replication data for: Consumption-Based Asset Pricing](http://thedata.harvard.edu/dvn/faces/study/StudyPage.xhtml?globalId=hdl:1902.1/UQRPVVDBHI).\" I downloaded the data, and called it into a few quick graphs. It took about five minutes. You could dress them up a good deal more; I just thought I'd show how this looks for someone who just wanted a quick look at the data."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"local({r <- getOption(\"repos\")\n",
" r[\"CRAN\"] <- \"http://cran.r-project.org\" \n",
" options(repos=r)\n",
"})"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"if(!require(plotly)) {\n",
" install_github(\"plotly\", \"ropensci\", quiet = TRUE)\n",
" }"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"library(plotly)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"py <- plotly(\"ggplot2examples\", \"3gazttckd7\")#Initiate Plotly graph object "
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"library(IRdisplay)\n",
"plotly_iframe <- function(url) {\n",
" # set width and height from options or default square\n",
" w <- \"700\"\n",
" h <- \"600\"\n",
" html <- paste(\"<center><iframe height=\\\"\", h, \"\\\" id=\\\"igraph\\\" scrolling=\\\"no\\\" seamless=\\\"seamless\\\"\\n\\t\\t\\t\\tsrc=\\\"\", \n",
" url, \"\\\" width=\\\"\", w, \"\\\" frameBorder=\\\"0\\\"></iframe></center>\", sep=\"\")\n",
" return(html)\n",
"}"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 15
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"display_html(plotly_iframe(\"https://plot.ly/~MattSundquist/1472\"))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<center><iframe height=\"600\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\"\n",
"\t\t\t\tsrc=\"https://plot.ly/~MattSundquist/1472\" width=\"700\" frameBorder=\"0\"></iframe></center>"
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 26
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"display_html(plotly_iframe(\"https://plot.ly/~MattSundquist/1475\"))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<center><iframe height=\"600\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\"\n",
"\t\t\t\tsrc=\"https://plot.ly/~MattSundquist/1475\" width=\"700\" frameBorder=\"0\"></iframe></center>"
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 19
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"display_html(plotly_iframe(\"https://plot.ly/~MattSundquist/1479\"))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<center><iframe height=\"600\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\"\n",
"\t\t\t\tsrc=\"https://plot.ly/~MattSundquist/1479\" width=\"700\" frameBorder=\"0\"></iframe></center>"
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 20
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"display_html(plotly_iframe(\"https://plot.ly/~MattSundquist/1481\"))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<center><iframe height=\"600\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\"\n",
"\t\t\t\tsrc=\"https://plot.ly/~MattSundquist/1481\" width=\"700\" frameBorder=\"0\"></iframe></center>"
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 21
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"display_html(plotly_iframe(\"https://plot.ly/~MattSundquist/1482\"))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<center><iframe height=\"600\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\"\n",
"\t\t\t\tsrc=\"https://plot.ly/~MattSundquist/1482\" width=\"700\" frameBorder=\"0\"></iframe></center>"
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 23
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"display_html(plotly_iframe(\"https://plot.ly/~MattSundquist/1470\"))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<center><iframe height=\"600\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\"\n",
"\t\t\t\tsrc=\"https://plot.ly/~MattSundquist/1470\" width=\"700\" frameBorder=\"0\"></iframe></center>"
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 27
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"display_html(plotly_iframe(\"https://plot.ly/~MattSundquist/1483\"))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<center><iframe height=\"600\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\"\n",
"\t\t\t\tsrc=\"https://plot.ly/~MattSundquist/1483\" width=\"700\" frameBorder=\"0\"></iframe></center>"
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 25
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# CSS styling within IPython notebook\n",
"display_html(getURL(\"https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css\"))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<style>\n",
" /*body {\n",
" background-color: #F5F5F5;\n",
" }*/\n",
" div.cell{\n",
" width: 850px;\n",
" margin-left: 10% !important;\n",
" margin-right: auto;\n",
" }\n",
" h1 {\n",
" font-family: \"Open sans\",verdana,arial,sans-serif;\n",
" }\n",
" .text_cell_render h1 {\n",
" font-weight: 200;\n",
" font-size: 40pt;\n",
" line-height: 100%;\n",
" color:#447adb;\n",
" margin-bottom: 0em;\n",
" margin-top: 0em;\n",
" display: block;\n",
" white-space: nowrap;\n",
" } \n",
" h2 {\n",
" font-family: \"Open sans\",verdana,arial,sans-serif;\n",
" text-indent:1em;\n",
" }\n",
" .text_cell_render h2 {\n",
" font-weight: 200;\n",
" font-size: 20pt;\n",
" font-style: italic;\n",
" line-height: 100%;\n",
" color:#447adb;\n",
" margin-bottom: 1.5em;\n",
" margin-top: 0.5em;\n",
" display: block;\n",
" white-space: nowrap;\n",
" } \n",
" h3 {\n",
" font-family: \"Open sans\",verdana,arial,sans-serif;\n",
" }\n",
" .text_cell_render h3 {\n",
" font-weight: 300;\n",
" font-size: 18pt;\n",
" line-height: 100%;\n",
" color:#447adb;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 2em;\n",
" display: block;\n",
" white-space: nowrap;\n",
" }\n",
" h4 {\n",
" font-family: \"Open sans\",verdana,arial,sans-serif;\n",
" }\n",
" .text_cell_render h4 {\n",
" font-weight: 300;\n",
" font-size: 16pt;\n",
" color:#447adb;\n",
" margin-bottom: 0.5em;\n",
" margin-top: 0.5em;\n",
" display: block;\n",
" white-space: nowrap;\n",
" }\n",
" h5 {\n",
" font-family: \"Open sans\",verdana,arial,sans-serif;\n",
" }\n",
" .text_cell_render h5 {\n",
" font-weight: 300;\n",
" font-style: normal;\n",
" color: #1d3b84;\n",
" font-size: 16pt;\n",
" margin-bottom: 0em;\n",
" margin-top: 1.5em;\n",
" display: block;\n",
" white-space: nowrap;\n",
" }\n",
" div.text_cell_render{\n",
" font-family: \"Open sans\",verdana,arial,sans-serif;\n",
" line-height: 135%;\n",
" font-size: 125%;\n",
" width:750px;\n",
" margin-left:auto;\n",
" margin-right:auto;\n",
" text-align:justify;\n",
" text-justify:inter-word;\n",
" }\n",
" div.output_subarea.output_text.output_pyout {\n",
" overflow-x: auto;\n",
" overflow-y: scroll;\n",
" max-height: 300px;\n",
" }\n",
" div.output_subarea.output_stream.output_stdout.output_text {\n",
" overflow-x: auto;\n",
" overflow-y: scroll;\n",
" max-height: 300px;\n",
" }\n",
" code{\n",
" font-size: 78%;\n",
" }\n",
" .rendered_html code{\n",
" background-color: transparent;\n",
" }\n",
" ul{\n",
" /* color:#447adb; */ // colors text too\n",
" margin: 2em;\n",
" }\n",
" ul li{\n",
" padding-left: 0.5em; \n",
" margin-bottom: 0.5em; \n",
" margin-top: 0.5em; \n",
" }\n",
" ul li li{\n",
" padding-left: 0.2em; \n",
" margin-bottom: 0.2em; \n",
" margin-top: 0.2em; \n",
" }\n",
" ol{\n",
" /* color:#447adb; */ // colors text too\n",
" margin: 2em;\n",
" }\n",
" ol li{\n",
" padding-left: 0.5em; \n",
" margin-bottom: 0.5em; \n",
" margin-top: 0.5em; \n",
" }\n",
" /*.prompt{\n",
" display: None;\n",
" } */\n",
" ul li{\n",
" padding-left: 0.5em; \n",
" margin-bottom: 0.5em; \n",
" margin-top: 0.2em; \n",
" }\n",
" a:link{\n",
" font-weight: bold;\n",
" color:#447adb;\n",
" }\n",
" a:visited{\n",
" font-weight: bold;\n",
" color: #1d3b84;\n",
" }\n",
" a:hover{\n",
" font-weight: bold;\n",
" color: #1d3b84;\n",
" }\n",
" a:focus{\n",
" font-weight: bold;\n",
" color:#447adb;\n",
" }\n",
" a:active{\n",
" font-weight: bold;\n",
" color:#447adb;\n",
" }\n",
" .rendered_html :link {\n",
" text-decoration: none; \n",
" }\n",
" .rendered_html :hover {\n",
" text-decoration: none; \n",
" }\n",
" .rendered_html :visited {\n",
" text-decoration: none;\n",
" }\n",
" .rendered_html :focus {\n",
" text-decoration: none;\n",
" }\n",
" .rendered_html :active {\n",
" text-decoration: none;\n",
" }\n",
" .warning{\n",
" color: rgb( 240, 20, 20 )\n",
" } \n",
" hr {\n",
" color: #f3f3f3;\n",
" background-color: #f3f3f3;\n",
" height: 1px;\n",
" }\n",
" blockquote{\n",
" display:block;\n",
" background: #f3f3f3;\n",
" font-family: \"Open sans\",verdana,arial,sans-serif;\n",
" width:610px;\n",
" padding: 15px 15px 15px 15px;\n",
" text-align:justify;\n",
" text-justify:inter-word;\n",
" }\n",
" blockquote p {\n",
" margin-bottom: 0;\n",
" line-height: 125%;\n",
" font-size: 100%;\n",
" }\n",
" /* element.style {\n",
" } */ \n",
"</style>\n",
"<script>\n",
" MathJax.Hub.Config({\n",
" TeX: {\n",
" extensions: [\"AMSmath.js\"]\n",
" },\n",
" tex2jax: {\n",
" inlineMath: [ [\"$\",\"$\"], [\"\\\\(\",\"\\\\)\"] ],\n",
" displayMath: [ [\"$$\",\"$$\"], [\"\\\\[\",\"\\\\]\"] ]\n",
" },\n",
" displayAlign: \"center\", // Change this to \"center\" to center equations.\n",
" \"HTML-CSS\": {\n",
" styles: {\".MathJax_Display\": {\"margin\": 4}}\n",
" }\n",
" });\n",
"</script>\n"
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 28
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment