# Creating Croplines for IronViz - Guest Blog by Sam Parsons

**Creating Croplines for IronViz**

*The following is a guest blog post from Sam Parsons. Sam is a Senior Data Visualisation Developer at Dyson and is known to the community for his incredibly creative designs. He lives is from Chippenham, England and can be contacted on Twitter @SParsonsDataViz.*

Thank you to Kevin for offering to host this blog post, which also happens to be my very first blog post ever! In this post I would like to run through a particular section of my IronViz entry Sowing Seeds in America (which like this blog, was also a first IronViz entry for me).

My IronViz focused on how geography of the United States affected where different crops were being grown. In particular, there were three main elements to the viz:

1) I wanted to give context to the data we were seeing. I tried to do this using a translucent choropleth map, overlaid on a Mapbox map that accentuated the hills and mountain ranges of North America.

2) I also wanted to dig into how the percentage of crop per farm acreage differed between states and give indications on the distribution of the same measure for that state’s counties.

3) Finally, I wanted to explore each state by showing all crops within that state and compare how an individual crop type was favoured across the country.

**Creating Flow**

I personally feel that an important part of storytelling is to aid the flow for the reader - to help them through the viz and not over-complicate the analysis to which point you may lose your audience. Therefore, my desire was that sections 2 and 3 were to be linked with interaction. I wanted to avoid having a heavily sectioned design to the viz.

To create flow between middle and bottom sections, I decided to create lines that gave the viz some form and flow vertically between the sections. I decided to use strong straight lines going down and out, because I felt they connected well to the story and data, were geometrically interesting and I felt the lines resembled drilled crop lines in a field. In addition, I added drop-bar analysis and some more subtle curved lines to draw the eye in from the drop-bar chart to the single state map below. Finally, I added interactivity to highlight the bars when a state was selected.

**Calculating Coordinates for “The Flow”**

How did I create the lines that connect from the US Map at the top to the drop-bar chart below? The good news is it is surprisingly simple! I did this using Excel. There were NO Tableau calculations required!

The next few images will give you an idea of where I started with this viz and the initial colour scheme I was working with (I went back and forth on my colour palette, so throughout this blog post, you will see varying colours, mainly browns and greens). At the time of creating the lines, I knew the space I was working with under the map so I knew how big I wanted to make them (highlighted with the yellow box).

With this in mind I knew that I had a width of 400 pixels to work with at
the top. The wider section below,
however, would stretch across most of the dashboard. I decided to utilize 1500 pixels for this
leaving 50 pixels from the edges. The
lines would be created using polygons, which is the same technique I used to
create the Polygon Lion image in my vizforsocialgood viz.

To create these polygons, I needed to find seven points for each state to aid Tableau in drawing the polygons and put them in Excel as a new data set. Below is a rough sketch (forgive me as this was drawn around 1am in the morning!). This shows each point of a single polygon. Sketching this out helped me work out the calculations required to quickly produce all seven x-y coordinates for each of the states.

To create these polygons, I needed to find seven points for each state to aid Tableau in drawing the polygons and put them in Excel as a new data set. Below is a rough sketch (forgive me as this was drawn around 1am in the morning!). This shows each point of a single polygon. Sketching this out helped me work out the calculations required to quickly produce all seven x-y coordinates for each of the states.

As mentioned, I knew that the space I had at the top was 400 pixels wide
and the space I had at the bottom was 1500 pixels wide. From here I needed to work out where I would
start the first point for the first polygon state. Below is a drawing that I created when I had
more sleep. It shows the seven points
required and I’ve provided a breakdown of how I calculated the location of these
points for the first state polygon.

Point 1)

The bottom portion of my polygon chart was set to be 1500 pixels. This 1500 would act as my X axis…so I would have x axis figures running from 0 to 1500. I wanted to have the upper section (400 px width) centred perfectly over the bottom section (1500 px width). So I had to figure out where the first point on the top section would line up according to the 1500 px bottom section.

I first found the centre point of both. The centre for the bottom was 750 (1500/2) and the centre for the top was 200 (400/2). So the centre of the top corresponded with an x axis value of 750. But I needed the beginning of that 400 px, not the centre. So, I simply subtracted 200 to get to the beginning leaving me at an x axis value of 550.

The bottom portion of my polygon chart was set to be 1500 pixels. This 1500 would act as my X axis…so I would have x axis figures running from 0 to 1500. I wanted to have the upper section (400 px width) centred perfectly over the bottom section (1500 px width). So I had to figure out where the first point on the top section would line up according to the 1500 px bottom section.

I first found the centre point of both. The centre for the bottom was 750 (1500/2) and the centre for the top was 200 (400/2). So the centre of the top corresponded with an x axis value of 750. But I needed the beginning of that 400 px, not the centre. So, I simply subtracted 200 to get to the beginning leaving me at an x axis value of 550.

Even though it’s at the top, I set the y axis value at 0. So the first point was set at 550, 0.

Point 2)

Point two was just slightly to the right of point one. All I did was divide the total number of pixels
for the top section by the number of states to determine how wide each polygon
would be at the top – 400 / 50 = 8 px.
So to find the 2nd point of the polygon, I simply added 8px to the
x-coordinate of the 1st point and y remained the same. The result was an x-y coordinate of 558,0.

Point 3)

Point 3 was directly under point 2 so we know that this point would share
an x coordinate with point 2 (558). For
the y coordinate, I simply estimated what would be fit my space. I ultimately landed on 410. Now remember that we started at the top with
a y coordinate of 0 and now we are below that line. That would, in theory, mean a negative
figure. For now, we are going to use
positive numbers and just reverse the y axis when we build the chart. So, the x-y coordinate of point 3 is 558,
410.

Point 4)

Well, let’s skip point 4 for now and come back to it because it will be
much easier to calculate once we have point 5.

Point 5)

Point 5 is simply the first point in the bottom that measured 1500 (which
we are essentially calling our x axis).
That means the x coordinate of point 5 of our first state polygon would
be 0. As far as the y coordinate goes,
like before, I simply chose a value that fit the space and was about half the
size as the top section. I chose
200. So add 200 to the 410 to get
610. Point 5 landed at 0, 610.

Now back to Point 4).

Just like point 2, I knew that point 4 was just to the right of point
5. In order to figure out the width of
that polygon, I just needed to divide the total length of 1500 by 50 which came
to 30 px. So each state polygon would
measure 30 px meaning that point 5 would be at x-y coordinates of 30, 610.

Point 6)

Point 6 was directly below point 1 and directly to the left of point
3. So we could use the x coordinate from
point 1 (550) and the y coordinate from point 3 (410) resulting in 550, 410.

Point 7)

Point 7 is our last point required to join the polygon. This has the same coordinates as point 1,
550,0.

That is now the 1st polygon drawn.
To draw the other 49 states, I used a little maths:

Point 1 of the next polygon) its x-y coordinate is equal to point 2 of the
previous state coordinate

Point 2 of the next polygon) follows the same rules above, add 8px to
point 1 on the x-axis

Point 3 of the next polygon) its x coordinate is same as point 2 and y
coordinate is always 410px

Point 4 of the next polygon) is calculated by adding 30px to point 5’s x
coordinate and y is calculated by adding 200px to point 3’s y coordinate

Point 5 of the next polygon) its x-y coordinate is equal to point 4 of the
previous state coordinate

Point 6 of the next polygon) its x-y coordinate is equal to point 3 of the
previous state coordinate

Point 1 of the next polygon) its x-y coordinate is equal to point 2 of the
previous state coordinate

The starting points and math was built out in Excel then copied/pasted
down the sheet until all 50 states were plotted (see image below). For your viz, you can create any shape you
want and it doesn’t have to be straight lines.
The takeaway here is the technique, not the exact calculations and
shapes that I used.

**Tableau Time**

Now that I had all the coordinates, I was finally able to bring this into
Tableau. I opened a new Worksheet and
connected to the Excel file as a new data source.

In the worksheet, I put X onto Rows, Y onto Columns, State ID onto Detail,
changed the mark type to Polygon, and then put Polygon Path onto Path. As mentioned previously, I had to reverse the
y axis to ensure the proper lining up of these points.

I then blended my polygon data (primary data source on the worksheet)
using State Name only to my original full dataset (secondary data source on the
worksheet), and then added this also to Detail. Doing this allowed me to
control this polygon chart using actions from charts that were set up using the
original data set. At this point, my
canvas looked like the following:

Now to add this sheet to my dashboard.
The majority of my dashboard was floating, which gave me more creative
control over what was happening and layering of different charts. I then placed this polygon chart in a
position where it floated behind the choropleth map.

I then added a drop bar chart (a standard bar chart with the y axis
reversed) to show that actual measures for each state. These were lined up with the polygon chart.

As I mentioned above I wanted to add a more visual flow between the middle
and bottom sections and I intended to do this through interactivity and colour
(flash of yellow). I used a Set Action,
which was driven off of the Map and the Violin Plots. This set action targeted a set called “Set-Croplines”,
which was created on the new Polygon Data Set using State Name as the basis for
the set. The set up for both the action
and the polygon sheet is shown below.

The set was then placed on the Colour Mark on the polygon worksheet as follows:

I changed the colours to be dark brown for those that were “OUT” of the
set and bright yellow for those that were “IN” the set. This meant that when a user selected a state,
the state was added to the set, and the polygon was essentially highlighted in
yellow.

Although I won’t go into it in this blog post, I created another data set
to create curved lines that would continue from the drop bar chart to an
individual state map. This really
finalized the flow. This also had set
actions applied for highlighting.

I now had a visual connection between the top US map and the bottom
individual state map, which the user drives themselves. And I was also able to simultaneously
incorporate some measurements via the drop bar chart. In the end, this part of
the viz was easy to follow and aided the user through the story levels within
the viz. Not to mention, it was a
striking visual to focus and maintain interest in the viz.

This blog post focuses on one section of my IronViz entry, but I’d love it
if you would check out the full version where I finally settled on a green colour palette (ha!).

Okay, that’s it! I hope it was easy
to follow and thank you for reading my very first blog post about my very first
IronViz entry. If you have any
questions, please feel free to reach out to me on Twitter @SParsonsDataViz.

Thanks

Sam

Kevin Flerlage, May 15,
2019 | Twitter |
LinkedIn | Tableau Public

## No comments