移除長條

Julia 資料視覺化入門

Gustavo Vieira Suñe

Data Analyst

長條圖

顯示印度不同產品平均價格的長條圖。

Julia 資料視覺化入門

長條圖 vs 直方圖

  • 數值資料的分佈

顯示洋蔥與小麥價格分佈的直方圖。

  • 類別之間的比較

顯示印度不同產品平均價格的長條圖。

Julia 資料視覺化入門

我們的資料集

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
  • 平均價格(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 )
Julia 資料視覺化入門

建立長條圖

# 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)")

顯示印度不同產品平均價格的長條圖。

Julia 資料視覺化入門

水平長條圖

# 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)")

顯示印度不同產品平均價格的水平長條圖。

Julia 資料視覺化入門

按州別的產品

  • 篩選指定州別
filtered_product = filter(
    row -> row.State in ["Maharashtra", "Goa", "Gujarat"],
    product)
  • 依州別計算各產品平均價
# Group by state and product
filtered_grouped = groupby(filtered_product, [:State, :Product])

# Calculate average prices filtered_mean_prices = combine( filtered_grouped, :Price => mean )
Julia 資料視覺化入門

群組長條圖

# 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)")

顯示印度部分產品依州別分組、並列顯示的群組長條圖。

Julia 資料視覺化入門

堆疊長條

# 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)")

顯示印度部分產品依州別分組、以堆疊方式呈現的群組長條圖。

Julia 資料視覺化入門

一起來練習吧!

Julia 資料視覺化入門

Preparing Video For Download...