# 01 Lab [en] - Data Visualization
###### tags: `Data Visualization` `Tableau`.
[TOC]
# Introduction - purpose of the exercise
During the class you are to prepare a dashboard *(dashboard)* consisting of three sheets - visualisations *(sheets)* prepared in Tableau.
The excercise is divided into two parts - first is related to Poland, and second realted to Europe.
## a) Poland transport infrastructure
The presentation should include an illustration of the length of express roads and motorways in Poland in the last 5 years divided into voivodships - [check online](https://public.tableau.com/views/expressways_16463234081690/Dashboard1?:language=en-US&:sid=&:display_count=n&:origin=viz_share_link).
<a id="rys0"></a>

<center><small>Rys.0.1 Managerial dashboard - Poland.</small></center>
## b) European transport infrastructure

<center><small>Rys.0.2 Managerial dashboard - Europe.</small></center>
# 1. Basic information
## 1.1 The process of preparing a visualisation - Tableau
[Fig.1](#rys1) presents the main steps that make up the process of preparing a presentation in Tableau.
<a id="rys1"></a>
<center><small>Fig.1 BI visualization preparation process.</small></center>
## 1.2 Organization of visualization project files
A typical visualization project implemented within BI requires the construction of a repository consisting of at least several types of files:
1. *Data source* related files - these are files that store data, e.g: ***csv, xls, txt, ...***
Workbook *Tableau* related files - files with the extension ***twb***.
Files with so-called *extract* data sources Tableau *extract* data source files - files that store subsets of data extracted from a data source to optimize data access and provide functionality not supported by the original data source . [Detailed information from the manufacturer's website.](https://https://help.tableau.com/current/pro/desktop/en-us/extracting_data.htm) File extensions *extract* - **hyper**.
Files, so-called *packaged workbook* - file that combines Tableau workbook with *extract* data source into one entity - extension **twbx**.
:::warning
**Note** :warning:
It is recommended that you create a hierarchical, dedicated file structure to store data related to all projects carried out in class. As a rule, all files related to one project should be stored in one folder.
Below is a proposed example of a file organisation structure.
```graphviz
digraph hierarchy {
node [color=Red,fontname=Courier,shape=box]
edge [color=Grey, style=dashed]
NameSurname->{"01 lab" "02 lab" ".."}
"01 lab"->{"01 excercise" "02 excercise" "03 excercise"}
"01 excercise"->{"data source \nxls,csv,.." "Tableau workbook\n*.twb" "Tableau extract \n *.hyper" "Tableau packaged \nworkbook *.twbx"}
}
:::
## 1.3 Source data
### a) Poland
Source data for the presentation should be downloaded from the portal provided by the Statistical Information Centre - [**Local Data Bank**, so-called **BDL**](https://bdl.stat.gov.pl/BDL/).
* dataset name: *Expressways and motorways*,
* branch in BDL: *Data by domain $ Transport and communication $ Public roads*,
* display data for all provinces, **without aggregated data for the whole country**.
* download and save data in XLS and CSV format - Fig.2.

<center><small>Fig.2 Interface of downloading data in BDL.</small></center>
### b) Europe
Source data for the presentation should be downloaded from the Eurostat data portal - https://ec.europa.eu/eurostat/web/main/data/database
* dataset: Total length of motorways
* branch in database: All data ---> Tables by themes ---> Transport ---> Road transport ---> Total length of motorways (ttr00002)
To customize the dataset use the Data Browser to:
* change the coutries set,
* fit the time: from 2010 to 2021,
* change the data series: motorways and e-roads.

## 1.4 Tableau Public - creating an account on the server
In order to publish your prepared visualizations, you must have an account on a Tableau server. Tableau offers two types of servers:
1. commercial servers - license required; offers extensive methods for managing permissions and organizing published visualizations;
1. free server provided by Tableau, so called [*Tableau Public*](https://public.tableau.com/) - non-commercial server; limited ability to manage published visualizations.
# 2. Preparing visualisations in Tableau
## 2.1 Preparing the data source
### a) Poland
One of the files downloaded from BDL can be used as a data source.
:::info
:information_source: **important**.
Tableau processes data collected in a flat table, consisting of named columns (data series) and consecutive rows representing consecutive data records.
Tableau does not accept formatting in individual cells or **merged cells**.
:::
In the current exercise, I propose to use a downloaded file in *xls* format. This file should be modified so that each sheet in the workbook contains data for **one selected cetagory**, i.e. highways or motorways. Moreover, the data header should be simplified so that it contains one line - Fig.3.

<center><small>Fig.3 View of sheet after transformation.</small></center>
### b) Europe

<center><small>Fig.3b View of transformation configuration for downloaded data set .</small></center>
## 2.2 Definition of *Data Source* in Tableau
After starting Tableau, we need to define the *Data source* that we will use when preparing the visualization.
### a) Poland
In our case, we point to the prepared *xls* file and select the *expressways* sheet for analysis - Fig.4.

<center><small>Fig.4 Polish data source in Tableau</small></center>
### b) Europe

<center><small>Fig.4 European data source in Tableau</small></center>
### 2.2.1 Data series types
After defining the *data source*, it is necessary to check whether the types of individual data series (columns) proposed by the system by default agree with the type we expect. Figure 5 shows the data type selection interface in the context of the selected column.

<center><small>Fig.5 Data type selection dialog for a column.</small></center>.
### 2.2.2 Geocoding
For data series (columns) that have a geographical context, you can try the automatic geocoding offered by Tableau. To do this, a *Geographic role* must be assigned for the selected column - **in the example analysed, for the column *village* select: *geographic role*->*State/province***.
As a result of geocoding, the system will assign automatically generated geographical coordinates: latitude (*latitude*) and longitude (*longitude*) to the records in the selected column.
<iframe src="https://en.wikipedia.org/wiki/Geographic_coordinate_system" width=100% height=400></iframe>
## 2.3 Preparation of visualisation components
## 2.3.1 Bar chart (*horizontal bars*)
We first prepare the bar chart from Fig.0.
Tableau supports the *drag and drop* working technique - performing individual actions often comes down to dragging the relevant elements onto the selected context.
To prepare a visualisation:
1. select the data series to be visualised on each chart axis - drag the relevant series from the *Data* cockpit onto the *Columns* and *Rows* fields;

1. from the *Show Me* window select the target visualization type;

1. format the visualization using the *Marks* cockpit.

Assign the appropriate formatting for the attributes:
1. Colors - using the *drag and drop* method, let's drag the data series to be used to layer the chart onto the button,
2. Size,
Label - format the data labels. 4,
Tooltip - here we format the tooltips that automatically appear when we move the pointer over the data series.
Formatting can be performed in the context of a selected data series or all series presented in the visualisation (tab *All*).
### 2.3.2 Text table (*text table*)
Proceed as with the bar chart, only change the visualisation type to *text table* in the *Show Me* window.
### 2.3.3 Map
In order to prepare a map presentation, use the automatically generated geographical coordinates during geocoding: *latitiude* and *longitude*. These coordinates should be dragged in respectively:
* *latitude* $rightarrow$ Rows,
* *longitutde* $rightarrow$ Columns.
On the details attribute (*Details*) in the *Marks* cockpit, drag the data series you want to show on the map - in our case *village*.

In the next step you should:
* select the visualisation type - *map*,
* colour the map by the selected attribute - I suggest a data series corresponding to 2018,
* configure the data labels.
## 2.4 Preparing a management cockpit (*dashboard*)
To prepare the dashboard, select *New dashboard* from the bottom menu of the visualization tabs.

Using the *drag and drop* method, arrange the individual visualisations in the correct order on an empty working area.

What remains to be configured is:
* titles of individual visualisations - context menu, option *Edit title*,
* arranging the control components in the right place of the cockpit - as in [Fig.0](#rys0).
## 2.5 Publishing to the *Tableau Public* server
The final step is to publish the visualization on the *Tableau Public* server. To do this:
* on the *Data source* tab, change the connection type from *Live* to *Extract*,
* top menu: Server -> Tableau Public -> Save to Tableau Public; after providing login details, we choose a name for the visualization on the server and publish the visualization.
# Do-it-yourself task
As part of this exercise you should prepare and publish on your *Tableau Public* profile an analogous presentation illustrating the length of motorways in individual european countries :smile:
---
*[BDL]: Local Data Bank
*[BI]: Business Intelligence