Case Study: Visualizations

Case Study: Visualizations

This is the fifth in a series of blog posts designed as a DIY training course for using Displayr. This post illustrates a number of different ways to create, layout and format visualizations in Displayr.

You can view a video of this dashboard being created here.

Opening the document

If you have already created a document called Presidential MaxDiff from this post: Case Study: Advanced Analysis of Experimental Data (MaxDiff), we are going to keep using that document. Otherwise, click here, which will open up a copy of the document created in that earlier post. This will automatically be saved into your list of documents.

Using the slide master to create a consistent look and feel

A lot of time can be saved by setting up default appearances for fonts and slide backgrounds. This is done using the Page Master.

  • In the Ribbon, go to Appearance > Page Master (View).
  • Click on the Title Only master page, on the left under the Master tab.

Page Master instructions

  • Download the background image onto your computer.Trump title page
  • Press Insert > Image and select the background image file.
  • Send it to the back of the page: Appearance > Sent to Back (Arrange).
  • Select the text in the page title and change it to 16 point, bold, white. These font settings are in the Appearance tab of the Ribbon.
  • Download the cover image onto your computer.
  • In the Master tab, select the Title page, and then in the Ribbon select Insert > Image and select the cover image, press Open.
  • Resize the image from one of the corners so that it fits the page. This may be easier if you first use the Zoom options on the right side of the Home tab in the Ribbon.
  • Leave the slide master by clicking Appearance > Normal (View) from the Ribbon.
  • Create a new page. RibbonInsert > New Page > Title Only. You will see that it has been created using the template we created in the slide master.

In this case, I have included the title of the document on the cover image. If you were setting up this document as a template to use for future projects, you would instead use a more generic cover image that you would modify on a project-by-project basis.

Four bar charts on one page

We are going to create a page showing four bar charts. Most of the work goes into creating the first chart, which is used as a template for creating the remaining charts.

Politics page with 4 charts

Creating a chart to use as a template

  • Click into the title bar area (it says Click to add title)and type: Politics.
  • In the Ribbon, select Insert > Visualization (Analysis) > Bar Chart.
  • In the Object Inspector, change the Inputs DATA Data source to Link to variables in ‘Data’.
  • Click-and-drag 2012 Voting from Data Sets into the Variables in ‘Data’ box on the right.
  • In the Objector Inspector, check DATA MANIPULATION > Show as percentages
  • Check the Automatic option next to the  Calculate  button.
  • Next, we’re going to click on the Chart tab in the Object Inspector, and set:
    • DATA SERIES > Color palette to Custom color and click on Custom color > More colors and enter the color code (at the bottom): 3e7dccSetting custom color
    • Set FONT > Global font color to white.
    • Add data labels: DATA LABELS > Show data labels.
    • Remove the gridlines by unchecking GRIDLINES > Show gridlines.
    • Hide the horizontal-axis title by entering a space in VALUES (X) AXIS > Axis title.
    • Hide axis by unchecking VALUES (X) AXIS > Show axis.
  • Resize the chart so it is in the top-left quarter of the page.
  • While we can add a chart title to the chart itself, documents tend to look neater when the chart titles are added manually.
    • In the Ribbon, select Insert > Text Box (Text and Images).
    • Put the text box to the top-left of the chart. You can place a text box by clicking-and-dragging the desired area of the box.
    • Give it a title of 2012 Election in 11 point light grey, bold.

Adding the remaining three charts

Now we need to create three more charts. We can save a lot of time by just copying, pasting, and modifying the existing chart.

  • Select both the current chart and the heading (by holding the SHIFT key and clicking), and then in the Ribbon, press Home > Copy and then Home > Paste. Move the new chart to be in the top-right.
  • Change the title to 2016 Election (You may need to zoom in to select the text: Home > Zoom).
  • For the new chart, replace the 2012 variable with 2016 Voting:va
    • Drag across the 2016 Voting variable to the Object Inspector under Inputs > DATA SOURCE> Variables in ‘Data’
    • Remove the 2012 variable using the  X  button next to it (which appears when you hover the mouse over the variable name)
  • Hold down SHIFT and select both titles and both charts, and in the Ribbon use Home > Copy and Home > Paste and move them to be underneath.
  • Replace the data for the chart at the bottom with Trump approval and Trustworthiness respectively, resizing them vertically to make them look neat and updating the titles.

Adding a footer containing sample size information

With survey reporting, it is common practice to show sample size information. If we use charts (see Case Study: Analyzing Survey Data), we get sample size automatically placed on each chart. With visualizations, we need to manually add it (but the benefit is we can just have it once on a page).

  • In the Ribbon, Insert > More (Analysis) > Data > Sample Size Description
  • We can add custom text to the description. In the Objector Inspector, enter InputsFinal text as: ; data collected from 30 June to 7 July 2017.
  • In order to compute the sample size, Displayr needs to know which variable you want to use when computing the sample size (as you may have missing values, and it can only deduce this by looking at a variable). Set Complete data variable to Gender.
    • You can either drag Gender over from the Data Tree, or start typing Gender into the in the Complete data variable input box which pulls up Gender [Q1].
  • Check Automatic, to the right of  Calculate .
  • Now we change the appearance in the Object Inspector under Properties:
    • Under LAYOUT, set the Padding to 0.
    • Check Wrap text output.
    • And then under APPEARANCE set Font: Open Sans
    • Set the font size to 8.
    • Set the font color to a light grey (pressing the button).
    • Make the Background transparent.
  • Resize it to cover the entire base (the black bar at the bottom), except for the Displayr logo.

Six visualizations

Demographics slide - goal pic

We are now going to create a page containing six visualizations, as shown to the right. We will do this by copying the page we have just created and modifying it.

  • Click on the page called Politics in the Pages Tree on the left.
  • In the Ribbon, press Home > Copy and Home > Paste. 
  • Change the title of the newly-created page to Demographics.
  • Copy one of the charts and two of the titles on the page, resize and re-arrange, so that you have two rows of 3 charts (envisage a layout akin to the right here – we’ll be modifying the respective chart types in a moment).
  • Update the headings and data in the charts as follows:
    • Top-left: Gender (deleting the chart to leave a blank space). Use the Home > Delete in the Ribbon to delete a chart.
    • Change the top-middle heading to Age. Click on the chart and change the variable selected in Variables in ‘Data’ to Age
    • Next, Top-right: RegionRegion
    • Bottom-left: Population density – Rural/Urban
    • Then make Bottom-middle: Household structureHousehold structurew
    • Bottom-right: Household income Household income

Now let us make each chart prettier! We’ll skip over the Gender spot and come back to it last.

1. Age bar chart

We are going to vary the blue to make the visualizations on this page pop:

  • Click on the age bar chart
  • In the Objector Inspector, click on the Custom color button in ChartDATA SERIES
  • Press More colors and set it to R: 140, B: 183, G: 244 and press OK

2. Regional cartograph

A map is a more interesting way of showing geographic data than the bar chart:

  • Click on the chart at the top-right so that we can modify it.
  • Change Inputs > OUTPUT > Chart Type to Geographic Map.
  • Hide the legend: Un-check Chart > LEGENDShow legend if applicable
  • Change the colors to create a bit of color variation on the chart: Change Chart DATA SERIES > Color palette to Custom gradient.
  • Change the start and end colors of the gradient:
    • Gradient start > More colors: R: 174B: 229G229
    • Gradient end > More colors: R: 0B: 200G200

3. Bar pictograph of population density

bar pictograph is our term for bar charts where the bars are images rather than rectangles. Perhaps these are not the most scientific of charts, but the can make things a bit more interesting!

  • Click on the population density chart (bottom-left).
  • In the Data Tree (that is, under Data Sets), click on Rural/Urban and then select from the Object Inspector: DATA VALUES > Labels.
  • Replace the entries in the Label column, from top to bottom, with: >1M people, 100K to 1M, 10K to 99K, <10K, and Isolated.  By making these changes to the variable in the Data tree, we are ensuring that the changes will apply if we ever use this data again (i.e, they are remembered in the data, not by the visualization).
  • In the Object Inspector,
    • Change Inputs > OUTPUT > Chart Type to Bar Pictograph.
    • In the Chart tab, set APPEARANCE > Icon to Building.
  • Make it relatively small and place it on the bottom left of the screen.

4. Household structure donut chart

Value attributes example

We will represent the household structure data as a donut chart.

  • Click on the household structure chart.
  • In the Object Inspector on the Inputs tab change the OUTPUT Chart type to Donut.
  • In ChartDATA SERIES > Color palette change the setting to Custom gradient.
  • Change the start and end colors of the gradient:
    • Gradient start > More colors: R: 0B: 200G200
    • Gradient end > More colors: R: 62B: 125G204
  • Our chart is still a bit messy due to some of the long labels, so we will shorten them:
    • In the Data tree, click on Household structure, and then in the Object Inspector select DATA VALUES > Labels.
    • Replace all but the last two labels in the Label column with: With parents,  Alone,  With partner only, With children only, With partner & children and press OK.
  • Finally, we need to merge a couple of the categories. The most straightforward way of doing this is to:
    • Drag Household structure from the Data tree, on to the page to create a table. We are going to use this table temporarily to merge categories. Put the table somewhere out of the way (eg: in the very top-left of the page so it’s not on top of the other visualizations).
    • Click on the table and then on the row label Sharing accommodation and drag the “hamburger” (grey box with black horizontal lines) onto Other (please specify).
    • Looping hamburger merge
    • In the Ribbon, press Data Manipulation > Rename (Rows/Columns) and give it the name of Other. Note that the donut chart has automatically updated.
    • Click on the table again (so that the whole table, rather than just Other is selected).
    • Press Home > Delete (in the Ribbon) to remove the table.

5. Household income

We have too many income categories and need to merge some together. We can merge the categories on the table, and these merges will be automatically re-applied to the existing table. To do so:

  • From the Data Treedrag Household income onto the top-left of the screen, so that it covers the two-left most charts.
  • Click on Under $1,000 (it will get a dark border around it when you select it), hold down the SHIFT key on your keyboard and click on $25,000 to 29,999. All the cells should be selected.
  • In the Ribbon;
    • Press Data Manipulation > Merge (Rows/Columns).
    • Next press Data Manipulation > Rename (Rows/Columns), and give it a name of Under $30K and press Rename.
  • Using the same process, create groups of $30K to $59K$60K to $89K, $90K to $129K, $130K or more, and Don’t Know/Refused.  Categories can also be merged just by dragging and dropping.
  • Delete the table (Home > Delete). (We were only using it as an intermediary step.)
  • Click back to the bar chart, and in the Object Inspector:
    • Change Inputs > OUTPUT > Chart Type to Bar Pictograph.
    • In the Chart tab, set APPEARANCE > Icon to Money.
  • The resulting chart is a bit too hard to read. The rule that automatically works out how many icons to show for each number is not quite ideal in this instance. To override it, in the Object Inspector change Chart > APPEARANCE > Units per icon (scale) to 0.1 .

6. Gender

Pictograph close up - female male

We are going to represent gender as two images. This is a little bit fiddlier than anything we have done so far:

  • Drag Gender from the Data Tree onto the page. This will create a table for Gender.
  • We are now going to create an R Output that contains just the percentage of women in the sample:
    • Click on the gender table we just created and look at its name: Object Inspector > Properties > GENERAL > Name. It is table.Gender.
    • Ribbon: Insert > R Output (Analysis) and enter the R CODE (on the right) as Female = table.Gender[“Female”] and press  Calculate .  (Please note that it is important you type rather than copy and paste this text from this blog post, as the blog post has some weird invisible characters in it which can mess up the code.)
    • Create a second R Output containing the code Male = 100 – Female and press  Calculate .  
    • (Note: these R Outputs might be hard to see on the page as they have transparent backgrounds once calculated, and their default font is dark blue).
  • We have now created some useful intermediary calculations which we will refer to later. We will hide them so that they are not visible to people viewing the published document.
  • Hold down Ctrl on your keyboard, and click on the table and the two R Outputs that we just created.
    • In the Ribbon, press Appearance > Hide.
    • Drag them to be beneath the page. This last step is not strictly necessary, but it makes things neater.
  • We will now create the actual pictograph:
    • In the Ribbon, select Insert > Visualization > Pictograph > Single Icon
    • Resize on the page so that it fits in the right-half of the available space under the gender title.
    • In the Object Inspector, set:
      • Input data: Male
      • Maximum value: 100 (This tells Displayr that the input value, which is a percentage, is out of 100.)
      • Click Icon fill color > More Colors, and set this to custom R: 0, B: 200, G: 200
      • Data label suffix: % Male
      • Decimals shown: 0
      • Data label font-size: 10
      • Next make Data label color: white
      • Check Automatic (next to the  Calculate ).
  • Copy and paste the icon, putting the new version to the left of the first, and setting:
    • Input data: Female
    • Icon: Stick woman
    • Data label suffix: % Female

Using a Table as an input to creating a Visualization

If you have been doing this post while waiting for the calculations in Case Study: Advanced Analysis of Experimental Data (MaxDiff) to complete, please go back and finish that post now, as we need the outputs from that analysis for the rest of this post.

When we created the pictographs of the genders earlier, we used a table as an input. In this section, we will take this idea a bit further:

  • Create a new page. RibbonInsert > New Page > Title Only
  • Give the page a title of Most important capabilities in a president
  • From the Data tree (that is, under Data Sets), drag Preference shares from max.diff onto the left-side of the page.
  • By default, as the selected variables are numeric, Displayr shows the table as averages. Other statistics can be shown on the table. From the Ribbon, select Home > Statistics – Cells (Data Selection) > % Share, and remove the average by selecting Home > Statistics – Cells (Data Selection) > Average
  • The SUM shown on the bottom of the table is not so insightful, so we will remove it. Click on the table, and then click on the SUM category label, and select Data Manipulation > Delete (Rows/Columns) from the Ribbon.
  • We can further improve this visualization by sorting. Click on the table and then on % Share at the top of the table, and select RibbonData Manipulation > Sort > Sort by Values – Descending > % Share.
  • Hide this table. RibbonAppearance : Hide and drag it off the bottom of the table for neatness
  • Go back to the Demographics page in the Pages Tree, click on the donut chart and the sample size and select Home > Copy and then paste into onto the Most important capabilities… page, resizing the donut chart to take up most of the screen.
  • Click on the chart.
  • In the Object Inspector,
    • Change DATA > Data source to Use a table in ‘Pages’Table: Preferences shares from max.diff. If it doesn’t immediately refresh, change page and return to this page (we are working on this bug as I write. You may have to nudge the visualization’s sizing to get it to resize properly)
    • Click on Chart and change DATA SERIES > Gradient end to white.

Results from the table can also be used to create descriptive text on the page. The text will change if the person viewing the document applies filters, or when the data changes. Start by pressing RibbonInsert > R Output (Analysis) to create an empty R Output.

nms = names(sort(table.Preference.shares.from.max.diff, decreasing = TRUE))
nms = nms[!nms %in% "SUM"] # Removing the 'SUM' cateogry
paste0("The capability most desired in The President is ", nms[1], ", followed by ", nms[2], ", and ", nms[3],".")
  • In the Object Inspector, 
    • Enter the R CODE shown above. (The only hard bit of this code is to know that paste0 is R-speak for combining everything together.)
    • Tick the Automatic box, next to the  Calculate  button.
    • Change the basic formatting of the textbox as follows:
      • Properties > LAYOUT and check Wrap text output.
      • Properties > APPEARANCE > Font: Open Sans.
      • Press B for bold.
      • Set the font color to a light grey.
    • Resize it and place where you like.

The finishing touch is to include the page footer, which tells us about the sample size of the data set. To add it:

  • Click back to the Demographics page (in the Pages Tree).
  • Select the footer.
  • Press RibbonHome > Copy.
  • Return to the Most important capabilities… page and then  RibbonHome > Paste.

Ranking plot

Finally, we will create a ranking plot.

  • Ribbon Insert > New Page > Title Only
  • Title: Trait importance by approval
  • RibbonHome > Paste should paste the footer in (assuming you have done everything in the order described in this post).
  • From the Data tree, drag Preference shares from max.diff onto the left-side of the page (as a table). Note that the data is still rank ordered, and the SUM is still missing. These changes have “stuck” to the data from our previous visualization.
  • Slowly drag Trump approval across, releasing it in the Columns box.
  • Now let’s change the statistics in the cells,
    • From the Ribbon, select Home > Statistics – Cells (Data Selection) > % Column Share,
    • Remove the average by (de)selecting Home > Statistics – Cells (Data Selection) > Average
  • And then change the table into a chart:
    • Home > Chart > Ranking Plot (see the picture below). This is one of the exceptions that make the rule, where the rule is that (almost) all of the interesting ways of viewing data are in the Insert Visualization menu. See Charts versus Visualizations versus Plots: Which to Use When for more about charts versus visualizations.
    • Resize the chart to cover the entire page
  • Now let’s customise the chart by going over to the Object Inspector:
    • Click on ChartCOLUMN LABELS and set the font color (A) to white.
    • FORMATTING > Show Values to Yes – Right.
    • Sett the font size to 8.
    • Set NUMBER OF RANKS to 16 (by default, it only shows the top 10, but we have 16 categories in this study).
    • Click on NUMBERS and set the font color (A) to white.

Finishing up

  • Create a new page. Ribbon: Insert > New Page > Title Page.
  • Delete the text boxes.
  • Set the label for the page. Select the page in the Pages Tree, and then in Object Inspector > Properties > GENERAL > Label to Title page.
  • Reorder the pages (in the Pages Tree), so that they are in order of:
    • Title page
    • Most important capabilities…
    • Trait importance by approval
    • Demographics
    • Politics
    • Model
  • Create filters
    • Hold down the Ctrl key on your keyboard, and using your mouse click on the following variables in the Report tree: Gender, Age, Region, Rural/Urban, Household structure, and Employment Status.
    • Click on the Insert tab in the Ribbon and select, on the far right, Insert > Utilities > Filtering > Create filters from Selected Data and press OK. You will see that some new variable sets have been added to the Data tree. These variable sets contain variables that can be used to filter the data.
  • To publish the document, select Ribbon: Export > Web Page > Snapshot and View > A link that can be used by anyone > Open in a new tab.
  • This takes us to view mode.
    • Click on the page Most important capabilities in a president Pages Tree in the and note that Good in a crisis is the second most important capability listed in the textbox at the top of the screen.
    • Click Filters (in the top right), select South, and click OK. The text has automatically updated, with Christian now second-most important. We could also get the donut plot to re-sort, but I prefer not to as it makes it easier to understand how sub-groups compare.

Try it for yourself

Click here to sign into Displayr and edit the document that I created when writing this post.

To learn a bit more about Displayr, please read Case Study: Automatically Updating Interactive Time Series Dashboard, which introduces you to the creation of charts, tables, filters, and reports, from raw data files.

About Tim Bock

Tim Bock is the founder of Displayr. Tim is a data scientist, who has consulted, published academic papers, and won awards, for problems/techniques as diverse as neural networks, mixture models, data fusion, market segmentation, IPO pricing, small sample research, and data visualization. He has conducted data science projects for numerous companies, including Pfizer, Coca Cola, ACNielsen, KFC, Weight Watchers, Unilever, and Nestle. He is also the founder of Q, a data science product designed for survey research, which is used by all the world’s seven largest market research consultancies. He studied econometrics, maths, and marketing, and has a University Medal and PhD from the University of New South Wales (Australia’s leading research university), where he was an adjunct member of staff for 15 years.