Created
July 21, 2014 00:43
-
-
Save randyzwitch/954497fe4add45e29f76 to your computer and use it in GitHub Desktop.
Re-creating WordPress chart using Plot.ly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Plotly, DataFrames | |
Plotly.signin("username", "api-key") | |
#Read in data | |
df = readtable("visits_visitors.csv") | |
#Create page views plot | |
views = [ | |
["x" => df[:Month], "y" => df[:Views], "type" => "bar", "name" => "Views", "marker" => ["color" => "rgb(39, 141, 188)"]] | |
] | |
#Create visitors plots | |
visitors = [ | |
["x" => df[:Month], "y" => df[:Visitors], "type" => "bar", "name" => "Visitors", "marker" => ["color" => "rgb(0, 0, 153)"]] | |
] | |
layout_views = [ | |
"xaxis" => ["autotick" => false, "dtick" => 1, "tick0" => 1], #Seems to have no effect | |
"bargap" => 10, #Seems to have no effect | |
] | |
layout_visitors = [ | |
"showlegend" => true, | |
"legend" => ["x" => 1, "y" => 1], | |
"yaxis" => ["autotick" => false, "dtick" => 2000], | |
"xaxis" => ["autotick" => false, "dtick" => 5, "tick0" => 4], | |
"bargap" => 0.1, | |
"barmode" => "overlay" | |
] | |
#Make API calls - second call allows for overlaying graphs | |
response = Plotly.plot(views, ["filename" => "basic-bar", "fileopt" => "overwrite", "layout"=> layout_views]) | |
response = Plotly.plot(visitors, ["filename" => "basic-bar", "fileopt" => "append", "layout"=> layout_visitors]) | |
#Print inline in IJulia Notebook | |
s = string("<iframe height='450' id='igraph' scrolling='no' seamless='seamless' src='", response["url"], | |
"/1000/450' width='1050'></iframe>") | |
display("text/html", s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment