Last week I posted an article about exploring chronic disease data with data visualizations, in particular bubble, plots using Density Design’s free online visualization tool RAW. As I was putting that article together I came across another free online data visualization tool, Plotly.
Plotly is new, only about 5 months old, and like RAW, is in beta. I thought it would be interesting to try some of the same chronic disease data I used in RAW to kick the tires on Plotly. Below is an interactive data visualization of the Correlation of Physical Activity to Obesity and Deaths Due to Heart Disease that I explored in the my previous article and below that I’ll outline the basic process of making your own similar bubble chart using Plotly. Note: I’ve noticed that the embedded iFrame doesn’t always load as it should. If you only see an empty white space below, refresh your browser. That often works for me to ‘force’ the embedded iFrame plot to show up. If that doesn’t work, see the larger plot hosted on the Plotly site.
See a larger version on the Plotly site.
Like, RAW, Plotly makes it easy to grab some data and either upload it or paste it in. Since I already had my heart disease correlation to obesity and physical activity in a Google Docs spreadsheet I just grabbed that same data and pasted into Plotly’s grid. Here’s a look at my data from Google Docs in the image to the right.
Then, in Plotly, just click on the + sign in the top left corner and select Grid.
You can also enter the data by typing directly into the grid or upload a file.
Next, select Make a Plot and choose Bubble charts from the drop down menu.
In the UI that follows you select which of your columns you want to be on the x axis and which on the Y axis by clicking the corresponding intersecting row and column. Here I’ve selected that I want Physical Activity to be on the X axis and Obesity Rate on the Y Axis.
The next part is a little less intuitive. On the left of you’ll see a box with some instructions:
Choose x and y columns to graph. Then choose a “Size By” column to make the size of each point proportional to the row in this column. The optional “Text” column adds hover or floating text to each point.
To associate values in your data to the size of the bubbles in the bubble chart you need to click the Size By button on the left to get a new row at the top that will be labeled “S” and then you click which column of data you want to represent the bubble sizes. Here I selected the Heart Disease column to represent the bubble size.
There are currently no instructions for the Group By option. From what I can tell it will allow you to group some of the data and color code it. In my example, I used the Group By for the state name to give each state a different color. To get a new row that allows you to select a column or columns to group by, you need to select the Group By button in the options pane to the left of the data grid. Click the Text button to get a new row to define what columns should show up as text.
Finally, click the blue button that says Bubble Chart . Clicking that button will open up a new tab within Plotly with your bubble chart.
There are a lot of options for styling the plot, adding annotations, etc. Click on the main title and axes labels to type in a new title and label the x and y axes. In my exploration of the tool I kept the styling to a minimum within Plotly in order to get a better idea of how it compares with Density Design’s RAW tool with just the default settings. The main parameters I’ve adjusted in this example are the layout to change the width and height of the plot and hiding the legend. To change the layout size, click on Layout to get access to the width and height fields. If you plan to embed the iFrame version of the plot into your website or blog you’ll definitely want to adjust the width and height. More about this later.
To turn off the legend, click on Legend and select the Hide button from the Visible? option. Most of the time you would probably want the legend but in this example I didn’t think it really added any value since it was just showing the color for each state.
You also have a few options for downloading and exporting your plot. You can download it as a .png, .PDF, .svg, or .eps. Click the Download menu item to get access to those options.
The plot is available in its fully interactive glory on a page hosted at Plotly. The URL for this link can be found on your main dashboard that shows all of your files. Click on the blue file folder icon in the top left corner to access that.
Tips for Embedding an iFrame of your Plotly Bubble Chart in WordPress
You can also embed the interactive version of the plot on your own website or blog by using iFrame. I’ve found some glitches in displaying embedded iFrames within WordPress so you may need to set the size of the Plotly chart within Plotly to a size that will fit within your WordPress page or else your embedded iFrame will likely be larger than your page on your website and may not show up at all (I think this is a WordPress issue and not a Plotly issue). While in Plotly and editing your plot, click the Layout menu item and edit the width and height. If you want to embed your plot on a WordPress blog or similar blog structure you’ll want to know how wide articles are on your website, measured in pixels. For this site, the main content area of my articles is just over 600 pixels wide since the sidebar on the right side takes up several hundred pixels of width of the site. So, I changed my width and height of my plot to both be 600 pixels. That width that you set includes the margins and legends of the plot, so the width of the actual graph in my plot is only about 445 pixels wide.
Once you have your plot the size you need to fit into your website it’s time to get the iFrame embed code. Below is an example of an iFrame embed code that would embed my plot at 600 pixels wide by 600 pixels high.
Swap in your URL and edit the width and height values to match the size that you edited within Plotly.
That’s the basics of creating a bubble chart in Plotly to show correlations in your data. I’d encourage anyone to give it a try that wants to quickly explore correlations between 3 and even 4 variables. As far as formatting the bubble chart, Plotly does a much better job than RAW. With RAW, you’ll need to adjust the axes in Adobe Illustrator if you don’t want some of your bubbles lying right on top of an axis grid line. I also really like the ability to embed the fully interactive version of the plot. Plotly makes it very easy to create an interactive visualization to explore correlations – a great tool to explore correlations in health and health care data. So far, the main feature missing that I think would make Plotly’s bubble charts even better is to have the ability to display some corresponding text for each bubble that shows up without any rollover required, and then on rollover show the remaining data.
Apparently, there’s currently not an easy way to do this. Update: Apparently this is available; Check under Traces –> Style –> Lines / Markers. See Jack’s comment below for more.
For more information about the bubble charts, the Plotly team recently published a nice article about the Power of Bubble. Good luck and have fun playing with Plotly!