Charting with Plotly
What is Plotly?
Plotly is an online analytics and data visualization tool, headquartered in Montreal, Quebec. Plotly provides online graphing, analytics, and stats tools for individuals and collaboration, as well as scientific graphing libraries for Python, R, MATLAB, Perl, Julia, Arduino, and REST.
Plotly was built using Python and the Django framework, with a front end using JavaScript and the visualization library D3.js, HTML and CSS. Files are hosted on Amazon S3.
Other chartbuilders out there
Why Plotly
- Plot.ly has a graphical user interface for importing and analyzing data into a grid and using stats tools.
- Graphs can be embedded or downloaded.
- API libraries for Python, R, MATLAB, Node.js, Julia, and Arduino and a REST API.
- Figure Converters which convert matplotlib, ggplot2, and IGOR Pro graphs into interactive, online graphs.
Sign up
Visit the Plotly feed page
This is where all the recent charts people have made are displayed.
Now you can see the underlying data structure behind the visualization.
Click SAVE if you want to save a copy of it to your list of projects.
Make a chart
Let’s start from scratch.
]
And select Chart.
Preparing the data
Let’s use the Hamilton grosses data.
On the left, click the pulldown menu in Chart Type and click line plot.
For the X, select column A.
For the Y, select column B
According to this chart, Hamilton is making less money over time. Does that make sense?
Take a look at the X axis.
It’s going in the opposite direction.
It sorts the column alphabetically.
It doesn’t realize that it’s a date.
Note This is the scourge of working with data. The programs you’ll work with will do its best (or not try at all) to guess what format the data you’re trying to use is. But often times it gets it wrong, so it’s up to us humans to tell the program what the data is so it will do what we want to do with it.
We need to turn that dates column into a format that can be sorted easily.
Let’s go back to the Hamilton data page and this time copy and paste the data into a Google Sheet.
If it is going to sort ascending and descending, we need to change the format so that when it sorts, it does so logically.
So we need to tell Google Sheets to transform the dates column into years, months, and date.
Because that numerical order will sort correctly.
Click Format > and look for the format 2008-09-26 because that’s the best way (Not the Date 9/26/2008 option because if you think about it, it will group the months from different years together, which is not correct)
Great!
Bring that data back into Plotly.
Before we move on, let’s clean things up a bit.
We want to give the header columns the proper names.
Right click the space next to the header column and select Use row as header.
But now we’ve got an extra row that will only mess things up when we visualize the data.
So get rid of it.
Right click the row header next to it and select Remove selected rows.
Before we try to chart it, don’t forget to sort the dates column ascending.
On the left, click the pulldown menu in Chart Type and click line plot.
For the X, select column Week Ending.
For the Y, select column Gross.
For Hover Text, select column Gross.
Click into the title and now you’ve got a chart!
You can style it more with the Style tab on the left.
Click Save and name the plot and data file for future reference.
You’ll get a link, and when you follow it, click the Export button.
If you want, you can save it as an image and edit it in Photoshop or Illustrator.
Or you can take the embed code and put it in a website.