Dropping Bars

Introduction to Data Visualization with Julia

Gustavo Vieira Suñe

Data Analyst

Bar charts

A bar chart displaying the average prices of different products in India.

Introduction to Data Visualization with Julia

Bar charts vs histograms

  • Distributions of numerical data

A histogram displaying the distribution of onion and wheat prices.

  • Comparison of categories

A bar chart displaying the average prices of different products in India.

Introduction to Data Visualization with Julia

Our dataset

Date State Centre Product Price
APR-2001 Andhra Pradesh Chittoor Bathing Soap 10.0
APR-2001 Andhra Pradesh Chittoor Ink 10.0
... ... ... ... ...
SEP-2016 Bihar Patna Paper 38.0
SEP-2016 Bihar Patna Toothpaste 50.0
  • Mean prices (using Statistics)
# Group by each product
grouped = groupby(product, :Product)

# Calculate average prices mean_prices = combine( grouped, :Price => mean )
# Sort from higest to lowest sorted_mean_prices = sort( mean_prices, :Price_mean, rev=true )
Introduction to Data Visualization with Julia

Creating bar charts

# Create bar chart
bar(
    # Categories in x-axis
    sorted_mean_prices.Product,
    # Values in y-axis
    sorted_mean_prices.Price_mean,

# Set bar width bar_width=0.5
label=false, color=:royalblue1, ) title!("Product Prices in India") ylabel!("Average Price (Rupees)")

A bar chart displaying the average prices of different products in India.

Introduction to Data Visualization with Julia

Horizontal bar charts

# Create bar chart
bar(
    # Values in the y-axis
    sorted_mean_prices.Product,
    # Values in x-axis
    sorted_mean_prices.Price_mean,

# Set orientation to horizontal permute=(:x, :y),
label=false, color=:royalblue1, ) title!("Product Prices in India") xlabel!("Average Price (Rupees)")

A horizontal bar chart displaying the average prices of different products in India.

Introduction to Data Visualization with Julia

Products by state

  • Filter for selected states
filtered_product = filter(
    row -> row.State in ["Maharashtra", "Goa", "Gujarat"],
    product)
  • Average prices of each product by state
# Group by state and product
filtered_grouped = groupby(filtered_product, [:State, :Product])

# Calculate average prices filtered_mean_prices = combine( filtered_grouped, :Price => mean )
Introduction to Data Visualization with Julia

Grouped bar charts

# Create grouped bar chart
groupedbar(
    # Categories in x-axis
    filtered_mean_prices.Commodity,
    # Values in y-axis
    filtered_mean_prices.Price_mean,

# Define groups group=filtered_mean_prices.State,
color=[:teal :yellow2 :tomato3] ) title!("Prices in India by State") ylabel!("Average Price (Rupees)")

A grouped bar chart displaying the prices of some products in India grouped by state, with bars shown side-by-side.

Introduction to Data Visualization with Julia

Stack the bars

# Create grouped bar chart
groupedbar(
    # Categories in x-axis
    filtered_mean_prices.Commodity,
    # Values in y-axis
    filtered_mean_prices.Price_mean, 
    # Define groups
    group=filtered_mean_prices.State,
    color=[:teal :snow2 :tomato3],

# Stack the bars bar_position=:stack
) title!("Product Prices in India by State") ylabel!("Average Price (Rupees)")

A grouped bar chart displaying the prices of some products in India grouped by state, with stacked bars.

Introduction to Data Visualization with Julia

Let's practice!

Introduction to Data Visualization with Julia

Preparing Video For Download...