Make a Chart Out of Any Image Without Illustrator or Any Math!






When I had been using Tableau for about four months, I submitted my Candy Land viz to my second IronViz feeder (health and wellness), which would ultimately become my second top ten entry.  This viz walked you through the Candy Land game and certain stops on the way led you to dashboards that focused on the dangers of too much sugar.  One dashboard focused on the high levels of sugar in fast food.  Within that dashboard, I created a chart that showed the sugar content of every item on the McDonalds menu and the chart itself was shaped like the golden arches.  Items with high sugar content showed at the top and those with lower sugar content showed at the bottom.  (Click on the image below to be taken to the viz – and note that this was done before dashboard navigation buttons).  


If you reduce the size of the marks in this chart, it looks like the following:



I was able to create a bunch of points that drew the golden arches of McDonalds.  Ever since I created that viz, I had intended on writing about how I created that particular chart without Adobe Illustrator or any math.  I mentioned it in a short blog post that I wrote for what used to be KenFlerlage.com, but I never dug into the details.  I’ve told dozens of people how to do it, but never wrote about it.  I even told someone I was writing it well over a year ago…I just never did.  So, finally here is how you can create a chart using x, y coordinates of just about any shape you like without any math whatsoever.

Tools Required

Before I get started, I should note that you can do pretty much all of this with Adobe Illustrator.  Adobe Illustrator is an absolutely amazing tool, but it is expensive and has a bit of a learning curve, so this blog post will focus on doing it without Illustrator. 

We will be using a couple of tools, but please know that they are all very simple and you don’t have to be technologically savvy to use them.  Plus I’ll tell you everything you need to know. 

The main tool we will be using is the Spotify Coordinator tool.  This tool is pretty simple, you upload an image, tell it how many points to draw and it will provide you with all the x, y coordinates you need.  Then just bring them into Tableau, create a scatter plot with those coordinates and voila, you have your chart of some crazy image!  Okay, that’s all for my blog post…wait, no it’s not…it’s not that simple. 

The Spotify Coordinator tool requires you to use a SVG (Scalable Vector Graphic often referred to simply as a vector).  Before moving on, I’d suggest you read up on vectors. I wrote a blog post on Tableau’s website regarding vector mapping and at the top, I break down what a vector is.  It’s only two short paragraphs and worth a quick read. 

Okay, the problem is that the image you’re working with probably isn’t a vector.  So before we get into the Coordinator tool, let’s talk a bit about getting a vector to use for this purpose.

Vector Images

If you have an image in mind, the first thing you can do is see if you can find it as a vector.  There are numerous websites that allow you to download free vector images, such as Vecteezy and Freepik.  Just google “free vector images” and you’ll find a ton of websites, but keep in mind that most sites want to sell you images, so please make sure that you are looking only at the free images.  My favorite place to download vector images is The Noun Project.  The annual membership is worth every single penny, but if you don’t have a membership, you can still download images/icons free of chart if you provide attribution. 

When looking for an image, keep in mind that you are bringing in this image as x, y coordinates into Tableau.  So in most cases, fairly simple images will work best.  I’ve also had more luck with filled images than with outline images. 

Now, if you’re able to find what you need as a vector, then you are in business.  But what if you simply cannot find what you want in the form of a vector?  Truth is, there is a ton more availability of jpgs and pngs than there are vectors.  Well, if you’re struggling, there’s a solution to that as well. 

Let’s say we have this nice png of an elephant:





Well, you can convert that image to a vector.  One way of accomplishing this is to use Adobe Illustrator.  There are tons of tutorials out there regarding methods to convert a jpg or png to a vector image using AI – just google it.  But this blog post talks about how to do it without Adobe and I’ll walk you through how to do this.

First, download the Elephant.png image from my Google Drive so that you can walk through this example with me.  Now go to www.vectorizer.io.  In the middle of the screen, you should see a blue button where you can upload an image.  Go ahead and upload the Elephant.png image.  As soon as you do, you should see the tool converting it.  When it finishes, click the blue Download button and you'll have a vector.

You should note, the quality of your vector will depend on the quality of your original image.  If your original image is low quality, your vector will be as well.  Sometimes, online converters simply don’t do a perfect job.  They often come out looking much more pixelated than the original.  That said, you’re going to use it to generate x, y coordinates and bring into Tableau, so in most cases, it simply doesn’t matter.  (In some cases, it will, and you may need to go try again with another image). 

Note that some of the free conversion sites limit the number of times you can convert images in a given time period.  If that happens, just search for another tool – there are dozens. 

Spotify Coordinator

Okay, now that you have a vector, we can convert it to x, y coordinates.  For these examples, we will use the Elephant vector used in previous examples.  Hopefully you walked through the exercises to convert it, but if you didn’t, you can download it here.  Go to the Spotify Coordinator tool.  First, click the SELECT FILE button at the top and choose the Elephant.svg file.  Once you have selected it, a small thumbnail of the elephant will show at the top.

On the left, click Refine Dots.  Here is where you can select the number of points used to draw your image.  Use the Number of Points slider to choose the number.  For the elephant image, I’d suggest about 1000 points. 

Under Refine dots, there are many other options including Scale, Dot Radius, Color, etc.  I rarely change these settings as ultimately, we will be bringing the data into Tableau and they should not matter.  However, feel free to experiment with them.

Now click Get Coordinates on the left hand side.  When you do so, you should see a list of numbers in the white box on screen.  (If you do not, refresh the screen and start from the beginning as I’ve seen it not work properly once or twice).  Above the white box on the right, click the underlined csv link to download a csv of the x, y coordinates for your points.  You can download a json file if you prefer. 

Tableau

Now that we have a list of our x, y coordinates, let’s bring the data into Tableau.  Connect to the csv (text file) that you just downloaded.  It will bring in two fields X and Y.  Now go to a sheet and you’ll see these X and Y values showing as continuous measures.  Convert the X field to a Dimension.  This will automatically convert it to a Discrete Dimension.  Go ahead and convert it to Continuous.  Do the same thing with the Y field.  When finished, you should have a green X and green Y under Dimensions (Continuous Dimensions).

Place the X field on Columns and the Y field on Rows and you should see your image.  Almost every time I’ve used this technique, I’ve found that the picture either is upside down or mirrored.  I’m not sure what mechanism it uses to calculate the X and Y coordinates, but if it is upside down or mirrored, you can simply double-click the X-axis or Y-axis and choose Reversed to reverse the axis.  When finished, you should have something that looks similar to this:


Taking it Further

One thing I like to do before even bringing the data into Tableau is to number the rows (points).  In the csv file, I simply add a column, label it Point, and number the rows 1, 2, 3, etc.  When you bring it into Tableau, you will need to convert Point to a Discrete Dimension then place onto Detail (note, when doing this this way, you really don’t need to convert the X, Y coordinates to Dimensions, you simply add them to the columns and rows then place Point onto Detail).

Now that your points are numbered, you can do a few extra things with it.  For example, what if you wanted to connect the dots to draw lines or connect the shapes to create polygons?  All you really need to do is figure out what points to connect via lines or via polygons and you can set up your data to do exactly what you want.  Please note that this process is quite manual so will take some patience. 

Start by selecting the points you are interested in.  You can either select them all at once (as I do when I select the eye in the below gif) or you can press CTRL and make multiple selections (like with the tusk in the gif).  Once they are selected, you can hover over them, click the View Data button and export the list into a CSV (you can also add them to a set, which can make coloring the dots very simple).  Once you have a list of dots, you can then use that information to go back to your original data source and set up paths for drawing lines or polygons.  For example, once you have the points used in the eye, you can use another column to label a path by which you might draw a polygon (you’ll need another field to label the polygon as well).  Just know…this will take some time.


That said, if you really just want to draw lines, the easiest way is to use a ton of points so the dots run together to where they look like a line:





Okay, in summary:

    - Find Image

    - If it’s not already a vector, convert it

    - Upload to Spotify Coordinator

    - Set the number of points

    - Download JSON or CSV

    - Bring into Tableau

    - Change X & Y to continuous dimensions

    - Place on columns and rows

    - Reverse axis if needed

You might have seen this technique used a time or two.  Ken and I used this tool numerous times in our Christmas Dot to Dot game.  My colleague Jennifer Dawes used it to draw a timeline for her Dr. Seuss viz.  And I know there are many more than have done this as well.

That’s all I have for you today.  Thanks for reading and feel free to reach out at any time!

  
Kevin Flerlage, June 29, 2020



No comments:

Powered by Blogger.