Sitemap
Novita Fitriani

Novita Fitriani

Data Analysis and Data Science Enthusiast

Data Visualization — Choosing the Right Charts for Categorical and Numerical Data!

6 min readMar 10, 2024
Press enter or click to view image in full size
source

Data visualization is a technique for communicating data, representing data using graphs, charts, etc. The main aim of data visualization is to make information easy to understand. Studies show that people get information faster and better when it’s presented visually. It’s not just about showing graphs — we need to choose the right kind of graphs and communicate them well. This way, the data we share is accurate and helps in making better decisions.

Before we create visualizations, it’s important to know the type of data we’re working with. This understanding helps us pick the right way to show information. Different data needs different charts or graphs. When we know our data well, we can easily see patterns, share our findings clearly, and make better decisions based on accurate visuals. So, let’s begin by talking about the different types of data!

In a research study, there are two types of data: Categorical and numerical.

1. Categorical data

Categorical data represents qualitative variables that fall into specific categories or groups. There are two main types: nominal and ordinal.

Nominal data is like labels for categories without any order or ranking. For example, when we talk about gender, ethnicity, marital status, or car brands, each category is separate, and there’s no ranking or specific order. They’re just distinct groups, and we don’t use them to show any kind of numerical relationship.

Ordinal data represents categories with a natural order or ranking. Examples include education level (e.g., high school, bachelor’s degree, master’s degree), income brackets, or survey responses (e.g., strongly agree, agree, neutral, disagree, strongly disagree). The categories have a logical sequence but may not have consistent intervals between them.

Ordinal data is like categories that have a clear order or ranking. For instance, when we talk about education levels such as high school, bachelor’s degree, or master’s degree, or income brackets, and even survey responses like strongly agree, agree, neutral, disagree, and strongly disagree, these categories follow a logical sequence or ranking. However, the spaces or intervals between these categories might not always be the same.

2. Numerical data

Numeric data consists of numbers and is often quantitative in nature, and it comes in two main types: discrete and continuous.

Discrete numeric data means using whole numbers to count things or put them into categories. For example, you could count the number of students in a class, the books sold, or the cars in a parking lot using whole numbers.

Continuous numeric data refers to measurements, like height or temperature, where values can be any number within a range. It’s like measuring things precisely, allowing for a wide variety of values.

The next question is, how do we visualize each of these data types? Here, I’ll show you based on a project I’m working on in my bootcamp. It involves visualizing and analyzing the distribution of a categorical, continuous, categorical-continuous, and continuous-continuous feature using Python with seaborn and matplotlib.

Get Novita Fitriani’s stories in your inbox

Join Medium for free to get updates from this writer.

To create these visualizations, we used data available on Kaggle related to House Prices — Advanced Regression Techniques. Before we show you the pictures, let’s quickly understand our data. The dataset includes various factors like Garage type, Above Ground Living Area, and other characteristics. However, I won’t go into a detailed analysis here because our focus is just on making visualizations and briefly explaining the insights we get from them.

import pandas as pd
import numpy as np

import seaborn as sns
import matplotlib.pyplot as plt

1. Count of one categorical feature


garage_type_counts = df['GarageType'].value_counts()

plt.figure(figsize=(10, 6))
bar_plot = sns.barplot(
x=garage_type_counts.index,
y=garage_type_counts.values,
hue=garage_type_counts.index,
palette='bright',
legend=False)

for index, value in enumerate(garage_type_counts.values):
bar_plot.text(
index,
value + 0.1,
str(value),
ha='center',
va='bottom')

bar_plot.set_ylim(0, 1000)

plt.title('Count of GarageType')
plt.xlabel('Garage Type')
plt.ylabel('
Press enter or click to view image in full size

The ‘Attchd’ (Attached) garage type predominates, exhibiting a significantly higher frequency than other types. This suggests that the majority of houses in the dataset feature garages directly connected to the house. This preference for attached garages is likely driven by the convenience and accessibility they offer, contributing to easier access and enhanced security for homeowners.

2. Distribution of one continuous feature

fig, ax = plt.subplots()
sns.histplot(df['GrLivArea'], kde=True,color='purple')
ax.set(
xlabel="Above Ground Living Area",
ylabel="Frequency",
title="Distribution of Above Ground Living Area"
)

#Summary Statistics
summary_stats = df['GrLivArea'].describe()
print("Summary Statistics:")
print(summary_stats);

The mean above-grade (ground) living area (GrLivArea) for properties in this dataset is approximately 1515.46 square feet, with the majority falling within the range of 1129.5 to 1776.75 square feet. However, there are outliers with significantly larger areas, reaching a maximum of 5642 square feet. These variations likely stem from diverse architectural designs, lot sizes, and potential renovations, contributing to the broader spectrum of living spaces observed in the dataset.

3. Categorical-continuous

plt.figure(figsize=(12, 6))
sns.boxplot(x='GarageType',
y='SalePrice',
data=df, hue='GarageType',
palette='bright',
legend=False)

plt.title('Distribution of SalePrice for Each GarageType')
plt.xlabel('Garage Type')
plt.ylabel('Sale Price')

plt.show()

#Summary Statistics
summary_stats = df.groupby('GarageType')['SalePrice'].agg
(['count', 'mean', 'median', 'min', 'max', 'sum'])
print("\nSummary Statistics of Total SalePrice:")
print(summary_stats)
Press enter or click to view image in full size

The boxplot data shows that houses with BuiltIn garages have the highest average sale price, around $254,751, while those with CarPort garages have the lowest average sale price, about $109,962. Houses with an inside garage (BuiltIn) are more expensive because they usually have extra space and interior improvements, making them more valuable and comfortable, which drives up the selling price.

4. Continuous-continuous

plt.figure(figsize=(10, 6))
sns.scatterplot(
x='GrLivArea',
y='SalePrice',
data=df, color='blue',
alpha=0.5)

sns.regplot(
x='GrLivArea',
y='SalePrice',
data=df,
scatter=False,
color='mediumblue',
line_kws={'linewidth': 2})

plt.title('Relationship between GrLivArea and SalePrice')
plt.xlabel('Above Ground Living Area')
plt.ylabel('Sale Price')

plt.show()

#Summary statistics
summary_stats = df[['GrLivArea', 'SalePrice']].describe()
print("\nSummary Statistics:")
print(summary_stats)
Press enter or click to view image in full size

The positive correlation between GrLivArea and SalePrice suggests that larger living areas tend to fetch higher prices in the real estate market. This aligns with the common perception that larger living spaces offer more comfort, functionality, and desirability, leading to increased demand and subsequently higher sale prices. Additionally, larger living areas often imply more spacious and luxurious accommodations, which can contribute to their higher valuation.

There are many more examples I haven’t talked about yet. Let’s go deeper and talk about more things! I’m looking forward to sharing experiences from other projects that use different techniques for visualizing and analyzing data. Let’s keep exploring the interesting world of data and analysis together!

--

--

Novita Fitriani
Novita Fitriani

Written by Novita Fitriani

Data Analysis and Data Science Enthusiast