0% found this document useful (0 votes)
10 views33 pages

Data Visualization Tableau

All Practicals of Data Visualization lab

Uploaded by

pavitrarao2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views33 pages

Data Visualization Tableau

All Practicals of Data Visualization lab

Uploaded by

pavitrarao2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Practical-1

➢ Aim: Introduction to basic visualization tools.


Description:

Data visualization is the graphical representation of information and data. By using visual elements
like charts, graphs, and maps, data visualization tools help transform complex data sets into
accessible and understandable insights. It allows viewers to quickly identify patterns, trends,
correlations, and anomalies in the data, making it easier to interpret, analyze, and communicate
information.

Importance of Data Visualization:

1. Improves Understanding: Visualizations provide a clearer, more intuitive understanding of data


compared to raw numbers or text-based reports.
2. Reveals Patterns: Complex relationships and trends become more apparent through visual
means, helping to uncover insights that might be overlooked in tabular data.
3. Facilitates Decision Making: In business, research, or any other field, quick and accurate
decision-making is often based on data-driven insights, and data visualization provides those
insights more effectively.
4. Increases Engagement: People are generally more engaged with visual content than textual
data. Visualizations attract attention and maintain interest.

Types of Data Visualizations:

• Charts and Graphs: Such as bar charts, line charts, and pie charts that display individual
metrics.
• Heatmaps: Show data intensity through colors, useful for visualizing correlations and patterns.
• Maps: Geospatial data can be represented on maps to see trends based on geography.
• Infographics: Combine visuals and text to provide a comprehensive, easy-to-understand
presentation of the data.
• Dashboards: Interactive visual interfaces that display multiple data visualizations together, often
in real time.

Basic data visualization tools:

1. Matplotlib (Python)
• Purpose: One of the most popular Python libraries for creating static, animated, and interactive
visualizations.
• Key Features: Line plots, bar charts, histograms, scatter plots, pie charts, etc.
• Use Case: Widely used for generating quick and customizable plots in Python.

Example usage:

import matplotlib.pyplot as plt


plt.plot([1, 2, 3], [4, 5, 6]) # Simple line plot
plt.show()
2. Seaborn (Python)
• Purpose: Built on top of Matplotlib, Seaborn simplifies complex visualizations and adds
advanced statistical plots.
• Key Features: Heatmaps, violin plots, pair plots, box plots, etc.
• Use Case: Great for statistical data visualization and creating aesthetically pleasing plots.

3. Plotly (Python, JavaScript)


• Purpose: A versatile library for creating interactive, web-based visualizations.
• Key Features: 3D plots, geographical maps, interactive dashboards, etc.
• Use Case: Ideal for creating visually interactive charts and graphs that allow users to explore the
data.

Example usage:

import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
fig.show()
4. Tableau
• Purpose: A leading data visualization tool used to create interactive and shareable dashboards.
• Key Features: Drag-and-drop interface, real-time data integration, interactive visualizations.
• Use Case: Commonly used for business intelligence, reporting, and analytics with an intuitive
GUI.
• Features:
• Create visualizations using simple drag-and-drop actions.
• Can connect to various data sources (e.g., SQL, Excel, Google Analytics).

5. Power BI
• Purpose: A business analytics tool by Microsoft that enables users to visualize and share insights
from their data.
• Key Features: Real-time dashboards, data modeling, interactive visualizations, integration with
Microsoft Excel and SQL Server.
• Use Case: Used for business analytics and decision-making in corporate environments.

6. ggplot2 (R)
• Purpose: A powerful data visualization library in R that uses a grammar of graphics to create
complex plots.
• Key Features: Layered approach to creating plots, customization of axis labels, scales, and
themes.
• Use Case: Particularly useful in the R ecosystem for statistical data visualization.

Example usage:

library(ggplot2)
data(mpg)
ggplot(mpg, aes(x=displ, y=hwy)) +
geom_point() +
labs(title="Displacement vs Highway MPG")
7. Excel
• Purpose: A widely used spreadsheet tool with basic graphing capabilities.
• Key Features: Line charts, bar charts, scatter plots, pie charts, etc.
• Use Case: Common for creating quick charts and visualizations when working with small to
medium datasets.

Example Usage:

Product & Sales

2000

5000

3000

Electronics Clothing Groceries

These tools are essential for making data easily interpretable, whether for personal use, presentations,
or business reporting. Each tool has its strengths, and the choice of which to use depends on the
complexity of your data and the interactivity you need.
Practical-2
➢ Aim: What is data, where to find data, foundations for building data
visualizations, creating your first visualization.

Description:

✓ What is Data?

Data refers to raw facts, figures, or information that can be collected, analyzed, and interpreted. It
can take many forms:
• Numerical: Such as sales numbers, temperature readings, or prices.
• Categorical: Such as names, regions, or product types.
• Textual: Such as customer reviews, social media posts, or email contents.
• Temporal: Data collected over time, like daily stock prices, monthly website visits, or yearly
income growth.
In essence, data is the foundation for making decisions, discovering insights, and creating actionable
information that can help solve problems or improve processes.

✓ Where to Find Data?

Finding good-quality data is key to creating effective visualizations. Here are some places where we
can find useful datasets:
1. Public Data Repositories
o Kaggle: Offers free datasets for machine learning, data science, and visualization
practice. It’s a great resource for beginners and professionals alike.
o UCI Machine Learning Repository: A collection of datasets widely used in academic
and research settings.
o Google Dataset Search: A search engine for datasets across the web.
o Data.gov: The U.S. government's open data portal, offering datasets on various topics
like health, education, and finance.
o World Bank Open Data: Contains global data on a variety of development indicators,
economic factors, and more.

2. Data from APIs


o Many websites and services provide data through APIs, such as Twitter (for social media
analytics), OpenWeatherMap (for weather data), or financial data from Alpha Vantage.
o You can use these APIs to pull data directly into tools like Excel, Python, or R.

3. Public Datasets in Excel or CSV Format


o Many websites provide downloadable datasets in Excel or CSV format, which you can
open and manipulate easily. Websites like FiveThirtyEight or Awesome Public Datasets
have lists of open data.

4. Data from Personal or Organizational Sources


o This includes business data like sales numbers, user behavior data, or even your own
personal data like fitness tracking.
5. Web Scraping
o If the data you need is available on websites but not downloadable directly, you can use
tools like BeautifulSoup or Selenium (for Python) to scrape the data for your analysis.

✓ Foundations for Building Data Visualizations:

Before jumping into creating a data visualization, it's important to understand some basic principles
that guide effective visual communication.

1. Know our Audience


o Consider the knowledge level of your audience. Are they experts in the field, or is the
visualization meant for general understanding? Tailor your charts, labels, and complexity
accordingly.

2. Choose the Right Visualization Type


o Bar Charts: Good for comparing categories.
o Line Graphs: Best for showing trends over time.
o Pie Charts: Useful for showing proportions within a whole (although use them sparingly
as they can be difficult to interpret).
o Heatmaps: Best for displaying data density and correlation between two variables.
o Scatter Plots: Effective for showing the relationship between two continuous variables.
o Histograms: Ideal for displaying the distribution of a dataset.

3. Ensure Clarity and Simplicity


o Avoid cluttering a chart with unnecessary elements. Use clean and simple visualizations
that allow the data to speak for itself.
o Label axes, provide a legend (when necessary), and ensure titles are informative.

4. Use Color Wisely


o Use contrasting colors to highlight important data points. Make sure the color scheme is
intuitive and not distracting. Use tools like ColorBrewer to choose color palettes that are
visually appealing and colorblind-friendly.

5. Tell a Story with Data


o our visualization should convey a clear narrative. What’s the key takeaway? Focus on the
main insights and make sure the visualization serves that purpose.

6. Data Integrity
o Always ensure that the data is accurate and appropriately cleaned before visualizing it.
Incorrect or outlier values can lead to misleading visualizations.

✓ Creating our First Data Visualization:

Matplotlib is a great library for creating static visualizations. Let’s create a simple line chart to
visualize sales data using Python.
Step-by-Step Guide to Create a Visualization in Matplotlib:

1) Install Matplotlib: If we don’t already have Matplotlib installed, we can install it using pip:
pip install matplotlib

2) Prepare Your Data: Let’s create a simple dataset using Python. For this example, we’ll use
Month and Sales.
3) Create a Line Chart: Now, let’s create a basic line chart to visualize the sales over time.
4) Customize the Chart: You can enhance the chart by adding titles, axis labels, and a legend.
5) Output: Running the above code will display a line chart with the months on the x-axis and sales
on the y-axis. The chart will also include a title, axis labels, and a legend.

Source Code:

import matplotlib.pyplot as plt


# Sample data for sales over 5 months
months = ['January', 'February', 'March', 'April', 'May']
sales = [1000, 1500, 1300, 1700, 1600]

# Create a line chart


plt.plot(months, sales, marker='o', color='b', linestyle='-', label="Sales")

# Add title and labels


plt.title('Monthly Sales Data')
plt.xlabel('Month')
plt.ylabel('Sales ($)')
plt.legend()
# Show the chart
plt.show()

Output:
Practical-3
➢ Aim: Getting started with Tableau Software using data file formats, connecting
your data to Tableau, creating basic charts (line, bar charts, Tree maps) using the
show me panel.

Description:

✓ Introduction to Tableau
Tableau is a leading data visualization tool that helps users transform raw data into insightful,
interactive visualizations and dashboards. Known for its intuitive drag-and-drop interface, Tableau
makes it easy for anyone—from beginners to experienced data analysts—to create beautiful and
informative charts, graphs, and maps without needing extensive technical skills.
The main strength of Tableau lies in its ability to connect to various data sources, from simple
spreadsheets to complex databases, and instantly create dynamic visualizations. Whether you’re
working with sales figures, financial data, or customer demographics, Tableau enables you to analyze
trends, identify patterns, and present findings in a visually compelling way.

✓ Why Use Tableau?

• User-Friendly Interface: Tableau's drag-and-drop functionality makes it accessible for users of


all skill levels. You can build complex visualizations by simply selecting fields and placing them
into the workspace.

• Wide Range of Data Connections: Tableau can connect to various data sources, including
Excel, CSV, SQL databases, Google Sheets, cloud platforms, and more. This makes it ideal for
consolidating data from multiple sources into a single, unified dashboard.

• Interactive Dashboards: With Tableau, you can create dashboards that allow users to interact
with data in real time. Filters, tooltips, and parameter controls provide an engaging experience,
allowing users to explore data on their own.

• Advanced Visualization Options: Tableau provides a variety of visualization types, including


bar charts, line graphs, maps, scatter plots, and more. It also has advanced tools like calculated
fields, table calculations, and parameters, which enable in-depth analysis.

• Scalability and Collaboration: Tableau’s suite of products, such as Tableau Desktop, Tableau
Server, and Tableau Online, allow teams and organizations to share, collaborate, and scale data
insights across multiple departments.

✓ Who Uses Tableau?

Tableau is widely used across industries and roles:


• Business Analysts use it to turn data into actionable insights for decision-makers.
• Data Scientists leverage Tableau for exploratory data analysis and to visualize complex datasets.
• Marketing Teams use Tableau to track campaigns and audience metrics.
• Executives and Managers rely on Tableau dashboards for real-time insights and reporting.
✓ Supported Data File Formats in Tableau:

Tableau can connect to a variety of data sources, both file-based and server-based. Some common
file formats you can use include:
• Excel (.xlsx, .xls)
• Comma Separated Values (CSV) (.csv)
• Text files (.txt)
• JSON (.json)
• PDF (.pdf)
• Tableau Data Extract (.hyper, .tde)
• Spatial Files (like .shp for geographical data)
• Statistical Files (.sav, .sas7bdat)
• Google Sheets
Tableau also supports connecting directly to databases like MySQL, Microsoft SQL Server, Oracle,
and cloud-based sources like Google BigQuery, AWS, and Microsoft Azure.

✓ Connecting our Data to Tableau:

1. Open Tableau:
o When we open Tableau, we’ll see the Connect pane on the left. This pane allows us to
connect to different data sources.
2. Choose the Data Source:
o Click on the file type or database we want to connect to. For example, if we’re using an
Excel file, click on "Microsoft Excel."
3. Locate the File:
o After selecting our data type, browse our computer to find the file we want to use.
Tableau will load it and display a preview.
4. Data Source Setup:
o Once our data file is loaded, we’ll be taken to the Data Source tab.
o Here, we can drag tables or sheets (if using Excel) into the workspace, specify joins, and
view a sample of the data.
o we can also rename fields, change data types, and set relationships between tables if our
dataset has multiple sheets or tables.
5. Switch to the Worksheet:
o Once our data is connected and ready, click on the Sheet tab at the bottom to start creating
visualizations. This will take us to the main workspace in Tableau.
✓ Creating Basic Charts Using the Show Me Panel

The Show Me panel in Tableau is a quick tool for generating various types of visualizations based on
the data selected.
A. Creating a Line Chart
1. Select Data for the Line Chart:
o In our Data pane on the left, find the fields we want to plot. For example, if we have a
dataset with Country and boxes shipped, drag the country field to the Columns shelf and
boxes shipped to the Rows shelf.
2. Open Show Me:
o Open the Show Me panel by clicking the "Show Me" button in the upper-right corner.
3. Choose Line Chart:
o With our data selected, click the Line Chart option in the Show Me panel. Tableau will
automatically generate a line chart showing how many boxes are shipped in a country.
4. Customize:
o We can further customize our chart by changing colors, adding labels, or adjusting the
date aggregation (e.g., monthly, quarterly).

B. Creating a Bar Chart


1. Select Data for the Bar Chart:
o To create a bar chart, drag the country field to the Columns shelf and Sales to the Rows
shelf.
2. Choose Bar Chart in Show Me:
o In the Show Me panel, select the Bar Chart option. Tableau will transform the data into a
bar chart, with each country represented by a bar.
3. Customize the Bar Chart:
o We can adjust the color, size, or orientation of the bars. For example, if we prefer a
horizontal bar chart, switch the positions of the fields in the Columns and Rows shelves.
4. Add Details (Optional):
o Drag additional fields (e.g., Profit or Sub-category) to the Color or Label shelves to add
more depth to our chart.
C. Creating a Tree Map
1. Select Data for Tree Map:
o Tree maps are great for showing the proportion of parts to a whole. Select a categorical
field (e.g., Chocolate) and a measure (e.g., boxes Shipped).
2. Open Show Me:
o Open the Show Me panel and select the Tree Map option. Tableau will create a tree map,
where each category is represented by a rectangle whose size is proportional to Boxes
Shipped.
3. Customize the Tree Map:
o Add color to the tree map by dragging additional fields to the Color shelf.
4. Adjust Labels:
o To make the tree map easier to read, go to the Label shelf and drag any relevant fields
(like Category or Sales) there to label each rectangle.
Practical-4
➢ Aim: Create a bar chart for the categories of various books along with their
recommendations.

Description:

Creating visualizations in Tableau allows users to transform raw data into clear, interactive insights.
In this example, a bar chart will be used to display various book categories alongside the number of
recommendations each one has received.

Bar charts are ideal for comparing quantities across categories, making it easy to see which genres
are most popular or highly recommended.

By following a few simple steps in Tableau, users can connect their data, select appropriate fields,
and generate a visual that highlights key insights. This bar chart will provide a straightforward
comparison of recommendation counts across book categories, enabling viewers to quickly identify
trends and preferences.

Steps to Create a Bar Chart for Book Categories and Recommendations in Tableau:

1. Preparing the Data


Before starting, the user should ensure the dataset includes at least two columns:
• Category: The genre or type of the book (e.g., Fiction, Non-Fiction, Science, Fantasy).
• Recommendations: The number of recommendations for each category.

2. Connecting the Data to Tableau


• Open Tableau and connect to the dataset. For Excel or CSV files, go to File > Open and select the
data file.
• Tableau will display a preview of the data in the Data Source tab.

3. Creating the Bar Chart


• Open a New Worksheet:
o Open a new worksheet by clicking the Sheet tab at the bottom.
• Select Data for the Bar Chart:
o In the Data pane on the left, locate the Category field and drag it to the Columns shelf.
o Next, drag the Recommendations field to the Rows shelf. Tableau will automatically
create a bar chart that shows each category with a bar proportional to its number of
recommendations.
• Customize the Bar Chart:
o To apply different colors for each category, the user can drag the Category field to the
Color shelf in the Marks card, assigning a unique color to each bar for easy
differentiation.
o If needed, adjust the bar thickness, orientation, or alignment by modifying the Size setting
in the Marks card.
• Adding Labels:
o To display the number of recommendations on each bar, drag the Recommendations field
to the Label shelf in the Marks card. This will add labels showing the exact values on
each bar.
• Sorting (Optional):
o For clearer visualization, the user may sort the categories by the number of
recommendations. They can do this by clicking the Sort button above the axis on the right
side or by using the toolbar at the top.

4. Final Touches and Formatting


• Adjusting Axis Titles: If necessary, the user can rename the axis titles by double-clicking on
them. For example, they might rename "Recommendations" to "Number of Recommendations."
• Adding a Chart Title: The user can click on the title area at the top to add a relevant title, such
as "Book Categories and Recommendations."

5. Saving or Exporting
After completing the bar chart:
• The user can save their work in Tableau by going to File > Save As.
• Alternatively, they can export the chart as an image or PDF by selecting File > Export >
Image/PDF.

Output:
Practical-5
➢ Aim: Tableau calculations, overview of SUM, AVG, and Aggregate features,
creating custom calculations and field.

Description:

✓ Tableau Calculations Overview:


In Tableau, calculations are used to transform, analyze, and manipulate data directly within the
platform. They help users create new insights, make data comparisons, and refine visualizations.
Calculations can be simple or complex, and Tableau offers a variety of built-in functions for common
tasks, as well as the option to create custom calculations.

✓ Aggregate Functions:
Aggregate functions perform calculations on multiple values to produce a single summarized result.
They’re commonly used to summarize data, such as by calculating totals, averages, counts, or
finding the highest and lowest values. Some of the functions include:

1. SUM
• Purpose: This function adds up all values within a selected field.
• Use Case: Summing sales, profits, or any other metric to get a total value.
• Example: SUM(Sales) will calculate the total sales amount for all data points in the selected
scope.
• Result: A single value that represents the total.

2. AVG (Average)
• Purpose: This function calculates the average (mean) of values within a selected field.
• Use Case: Finding the average order value, average temperature, or any other metric where
an average insight is useful.
• Example: AVG(Sales) calculates the average sales amount by dividing the total sales by the
count of data points.
• Result: A single value that represents the average across all data points in the scope.
3. COUNT
• Purpose: This function counts the number of records or instances of a specific field.
• Use Case: Counting the number of customers, orders, or products in a dataset.
• Example: COUNT(Customer ID) counts the number of unique customers based on their IDs.
• Result: A single value representing the total count.
• COUNTD: Tableau also offers COUNTD, which counts distinct (unique) values in a field.
COUNTD(Product) would count each unique product only once.

4. MAX (Maximum)
• Purpose: Finds the highest (maximum) value within a selected field.
• Use Case: Identifying the maximum order amount, highest temperature, or maximum sales in
a category.
• Example: MAX(Sales) will return the highest individual sales amount from the data.
• Result: A single value representing the maximum.
5. MIN (Minimum)
• Purpose: Finds the lowest (minimum) value within a selected field.
• Use Case: Identifying the minimum price, lowest order amount, or smallest metric value in a
dataset.
• Example: MIN(Sales) will return the smallest individual sales amount.
• Result: A single value representing the minimum.

✓ Creating Custom Calculations and Fields


Custom calculations in Tableau are a powerful way to create new insights that may not be available
in the raw data. Custom fields can be used to segment data, create dynamic values, or perform
complex mathematical operations.
1. Creating a Calculated Field:
Steps to create a custom field {Cost} and {Profit Ratio} are:
• Right-click anywhere in the Data pane and select Create Calculated Field.
• In the calculation editor, name the field "Cost".
• Enter the following formula:

• Click OK to save the calculated field.

The new Cost field will now appear in the Data pane, and we can use it in our visualizations
as shown below:
✓ Quick Table Calculations
In addition to custom-calculated fields, Tableau offers quick table calculations, which can be applied
by right-clicking on any measure in the view and selecting Quick Table Calculation. These include
options like:
• Running Total
• Percent Difference
• Moving Average
• Rank
• Percent of Total
Quick table calculations are easy to use and ideal for rapid insights without the need for complex
custom fields.
Practical-6
➢ Aim: Connecting to Data and preparing data for visualization in Tableau.
Description:

✓ Connecting to Data in Tableau

1. Open Tableau and Go to the Start Page


o Begin by opening Tableau, which will display the Start Page with options to connect to
various data sources.
2. Choose the Data Source Type
o Under Connect, select the desired data source type. Tableau supports multiple formats,
including Excel, CSV, databases, and web connectors.

3. Select the Data File or Server Connection


o If using an Excel file, for example, click Microsoft Excel and locate the file on the
computer. Tableau will establish the connection and load the data.

4. Preview Data in the Data Source Tab


o Tableau will display the data preview in the Data Source tab, where tables can be viewed
and prepared for visualization.
5. Data Source Setup Options
o Drag tables or sheets (if using Excel) into the workspace.
o Specify joins and set relationships if multiple tables or sheets are being used.
o Rename fields, change data types, or modify relationships as necessary for a more refined
dataset.

6. Switch to the Worksheet


o After preparing the data, select the Sheet tab at the bottom to begin building
visualizations.

✓ Preparing Data for Visualization

Once the data is loaded, it’s important to prepare it for analysis and visualization:
• Inspect the Data Structure: Verify the imported data. Tableau will display tables and fields;
check if they are structured as expected.
• Join or Union Data: If working with multiple tables, you can join or union them to combine
data. Drag tables into the canvas and specify join conditions if required.
• Rename Fields and Adjust Data Types:
o Rename fields by double-clicking on the field name.
o Ensure each field has the correct data type (e.g., numeric, text, date) by checking the icon
next to it. Click the icon to change the type if necessary.

• Clean Data:
o Remove or hide unnecessary fields to keep your workspace organized.
o You can create calculated fields for more detailed insights (e.g., calculating "Cost" by
subtracting profit from sales).
Practical-7
➢ Aim: Editing and formatting axes, manipulating data in Tableau, pivoting
Tableau data.

Description:

In Tableau, editing and formatting axes, manipulating data, and pivoting data are key tasks for
creating polished, meaningful visualizations.

✓ Editing and Formatting Axes


Editing axes allows us to adjust the scale, range, and formatting of the axes in Tableau visualizations.

Steps to Edit Axes:


1. Open the Worksheet: Go to the worksheet where the chart is created.
2. Click on the Axis: Right-click on the axis (either X or Y axis) we want to edit.
3. Edit Axis: Select "Edit Axis" from the context menu.

4. Adjust Axis Settings:


o Range: Set the axis range to "Fixed" or "Automatic." If fixed, specify the minimum and
maximum values.
o Tick Marks: Choose how the tick marks will appear (automatic, fixed, or custom).
o Formatting: We can adjust the font, color, and alignment of the axis labels. Under the
"Format" pane, select "Axis" to make these changes.
o Number Formatting: Under the "Edit Axis" window, you can also change the format of
numbers (e.g., currency, percentage, decimal points).
✓ Manipulating Data in Tableau
Data manipulation in Tableau refers to the ways we transform and aggregate our data to prepare it for
visual analysis.

Steps to Manipulate Data:


1. Create Calculated Fields: To perform custom calculations on our data (e.g., adding a Profit
Ratio field), use Calculated Fields.
o Go to the Data pane, right-click and select Create Calculated Field.
o Enter the calculation.
o Name the calculated field and click OK.

2. Filtering Data:
o Drag fields to the Filters shelf to filter out specific data.
o We can filter by categorical values, range of dates, or numeric range.
3. Grouping Data: Tableau allows grouping values that are similar into a single group.
o Right-click on a dimension and select Group to create custom groups.

4. Sorting Data: We can sort data by ascending or descending order.


o Click on the field in the view and choose Sort to change the order.

5. Show Totals and Subtotals: You can enable Grand Totals or Subtotals to show aggregated
values at different levels in your data.

✓ Pivoting Data in Tableau


Pivoting allows us to switch data from a wide format to a long format, which is often necessary for
better visualizations or data analysis.

Steps to Pivot Data:


1. Go to the Data Source Tab: Open the Data Source view in Tableau.
2. Select the Fields to Pivot: Click and drag over the columns we want to pivot (usually multiple
measures or date fields).

3. Pivot the Data:


o Right-click on the selected fields and choose Pivot.
o Tableau will automatically create two new columns: Pivot Field Names and Pivot Field
Values.

4. Adjust the Pivoted Data:


o Rename the new fields as necessary for clarity.
o Now, we can use the pivoted fields for more flexible visualizations.
Practical-8
➢ Aim: To know about basic visualizations in R.
Description:

R is a powerful, open-source programming language and software environment primarily used for
statistical computing, data analysis, and data visualization. Developed by statisticians and widely
adopted by data scientists, analysts, and researchers, R has become one of the most popular
languages for data science.

✓ Key Features of R

• Statistical and Mathematical Functions: R offers built-in tools for statistical analysis, such as
hypothesis testing, regression, and time-series analysis, ideal for data-intensive research.
• Data Visualization: With base plotting functions and ggplot2, R allows for clean, customizable
visualizations.
• Extensive Package Ecosystem: CRAN provides thousands of packages for tasks like machine
learning, data wrangling, and bioinformatics.
• Data Manipulation: Packages like dplyr and tidyr streamline data cleaning and preparation.
• Reproducibility: R integrates with markdown tools, enabling reproducible reports that combine
code, results, and narrative.

✓ Basic Visualizations in R
A. Bar Charts
Purpose: Display categorical data as bars, with the height representing values.
Function used in Base R: barplot(height, names.arg)

Example:

library(ggplot2)

# Example data with corrected column names


data <- data.frame(BookCategory = c("Fiction", "Fantasy", "Science"), Recommendation =
c(120, 150, 90))

# Bar chart with customized color and reduced width


ggplot(data, aes(x = BookCategory, y = Recommendation)) +
geom_bar(stat = "identity", fill = "skyblue", width = 0.5) + # Color and width adjustments
theme_minimal()
B. Line Charts

Purpose: Show trends over time or ordered observations.


Function used in Base R: plot(x, y, type = "l")

Example:

# Line chart example

library(ggplot2)
time_data <- data.frame(Time = 1:5, Sales = c(20, 15, 30, 25, 35))

ggplot(time_data, aes(x = Time, y = Sales)) +


geom_line() +
theme_minimal()
C. Scatter Plot

Purpose: Visualize the relationship between two numeric variables.


Function used in Base R: plot(x, y)

Example:

library(ggplot2)

# Example data
data <- data.frame(Height = c(5.5, 6.0, 5.8, 5.9, 6.1),
Weight = c(150, 160, 155, 165, 170))

# Scatter plot with purple star-shaped points


ggplot(data, aes(x = Height, y = Weight)) +
geom_point(color = "purple", shape = 8, size = 4) + # Star-shaped points
theme_minimal()
Practical-9
➢ Aim: Basic dashboards in Tableau.
Description:

Creating a basic dashboard in Tableau allows us to combine multiple visualizations into a single
view, making it easy to analyze and present key insights. Here’s a step-by-step guide for creating a
basic Tableau dashboard:

1. Start a New Dashboard


1. Open Tableau and load the data source.
2. In the workbook, click on the New Dashboard icon at the bottom (it looks like a grid) or go to
Dashboard > New Dashboard in the menu.
3. The Dashboard Pane will open, and we’ll see the blank dashboard canvas and layout options on
the left side.

2. Add Visualizations to the Dashboard


1. Drag Sheets onto the Dashboard Canvas: In the Dashboard pane, we’ll see a list of all worksheets
and objects (such as text, images). Drag the sheets we want to include onto the canvas.
2. Arrange and Resize Visualizations:
o Tableau will automatically resize each visualization when added. We can adjust the layout
manually by dragging the edges of each sheet.
o Rearrange the order of sheets by dragging them within the canvas.

3. Adjust Dashboard Size


1. Choose Dashboard Size: In the Dashboard pane, set the size to Fixed Size, Automatic, or Range.
o Automatic will resize the dashboard to fit any screen, which is helpful for flexible
presentations.
o Fixed Size allows us to set specific dimensions (e.g., 1200 x 800).

4. Add Interactive Filters


1. Show Filters: To add filters that users can interact with, go to each visualization on the
dashboard, click the dropdown arrow, and select Filters. This will add filters based on the fields
in that sheet.
2. Sync Filters Across Sheets: If the filter should apply to multiple visualizations, click on the filter
card, select Apply to Worksheets, and choose either All Using This Data Source or specific
sheets.

5. Add Titles, Text, and Images


1. Title: Add a title for your dashboard by clicking Dashboard > Show Title. We can edit the title by
double-clicking on it.
2. Text and Images: Drag Text or Image objects from the Dashboard pane onto the canvas to add
descriptive text or images (e.g., logos).

6. Add Actions for Interactivity


1. Add Dashboard Actions: To make the dashboard interactive, go to Dashboard > Actions.
2. Create Actions:
o Filter Action: Allows clicking on one sheet to filter another.
o URL Action: Opens a webpage based on a selection (useful for linking to external
sources).
o Highlight Action: Highlights data points across multiple sheets.

7. Finalize and Preview the Dashboard


1. Preview: Click on Presentation Mode (the screen icon) to see how the dashboard will look
without the Tableau interface.
2. Adjust Layout: Make any final adjustments to the layout, resizing, and positioning for optimal
viewing.

Output:
Practical-10
➢ Aim: Data Aggregation and Statistical functions in Tableau.
Description:

In Tableau, data aggregation and statistical functions are essential tools for summarizing and
analyzing data. These functions allow users to calculate totals, averages, medians, percentiles, and
other descriptive statistics that help make sense of large datasets.

✓ Data Aggregation in Tableau

Data aggregation is the process of summarizing detailed data into more general, interpretable
information. Tableau offers several built-in aggregation functions:

• SUM: Adds up all the values in a field. Commonly used for total sales, revenue, etc.
• AVG: Calculates the average of values, useful for finding mean values like average sales or
profit per item.
• COUNT: Counts the number of values or records in a field. COUNTD (count distinct) counts
unique entries only.
• MIN: Finds the minimum value in a field, often used to locate the smallest quantity or earliest
date.
• MAX: Finds the maximum value, useful for identifying the highest quantity, price, or latest date.
• MEDIAN: Computes the middle value, which is less affected by outliers than the average.
• PERCENTILE: Calculates percentile rankings, useful in identifying performance thresholds,
like the 90th percentile of scores.

Applying Aggregation Functions

1. Drag a measure (e.g. Boxes Shipped) onto the Rows or Columns shelf in the worksheet.
2. Tableau automatically aggregates the measure, usually as a SUM by default.
3. To change the aggregation, click on the field in the view, then select Measure and choose another
aggregation type, such as AVG, COUNT, MIN, or MAX.
✓ Statistical Functions in Tableau

In addition to basic aggregation, Tableau provides statistical functions that allow for deeper data
analysis. Some commonly used statistical functions are:

• STDEV and STDEVP: These calculate the standard deviation for a sample or population,
respectively, which shows how spread-out data points are from the mean.
• VAR and VARP: These compute the variance for a sample or population, indicating the degree
of dispersion.
• Z-Score: Standardizes data by showing how far a data point is from the mean in terms of
standard deviations.
• CORR: Calculates the correlation between two fields, measuring the strength of their
relationship.
• COVAR: Calculates covariance, showing the direction of the linear relationship between two
variables.
• RANK and RANK_DENSE: Ranks values in a field, useful for ranking products, regions, or
employees based on sales or performance metrics.

Using Statistical Functions

1. Create Calculated Fields: To use statistical functions, we can create calculated fields that apply
them to your data.
o Go to the Data pane, right-click, and select Create Calculated Field.
o Enter a formula using the desired statistical function, for example: STDEV([Sales]) or
CORR([Sales], [Profit]).
2. Quick Table Calculations: Some functions, like Moving Average or Percent of Total, can be
accessed quickly by right-clicking on a measure in the view and selecting Quick Table
Calculation.
STDEV Usage Example:

CORR Usage Example:

You might also like