Công thức Series

Nhập môn Trực quan hóa Dữ liệu với Julia

Gustavo Vieira Suñe

Data Analyst

Tùy biến biểu đồ

# Create a violin plot
violin(
    streaming.Fav_genre,
    streaming.Insomnia,
    framestyle=:grid, label=false,
    linewidth=0,

# Fill properties fillcolor=:purple, fillalpha=0.75,
# Permute the axes permute=(:x, :y),
# Remove grid lines grid=:off, )
xlabel!("Mất ngủ tự báo cáo")

Biểu đồ violin ngang: mức độ mất ngủ theo thể loại nhạc ưa thích.

Nhập môn Trực quan hóa Dữ liệu với Julia

Series trong Plots.jl

  • Tập hợp điểm chung đặc tính vẽ
    • plot(x, y) là một series kiểu :line
  • Nhiều loại series: :line, :scatter, :histogram, :density, :bar
  • Một biểu đồ có thể có nhiều series
    • scatter(x, [y1 y2]) có hai series kiểu :scatter
    • Mỗi cột là một series
  • Plots.jl dùng công thức khác nhau cho mỗi loại series
    • Ta có thể tạo công thức tùy chỉnh!
Nhập môn Trực quan hóa Dữ liệu với Julia

Cuối cùng vẫn là plot

# Create a violin plot
plot(
    streaming.Fav_genre,
    streaming.Insomnia,
    framestyle=:grid, label=false,
    linewidth=0,
    fillcolor=:purple,
    fillalpha=0.75,
    permute=(:x, :y),
    grid=:off,

# Specify series type seriestype=:violin, )
xlabel!("Mất ngủ tự báo cáo")

Biểu đồ violin ngang: mức độ mất ngủ theo thể loại nhạc ưa thích.

Nhập môn Trực quan hóa Dữ liệu với Julia

Công thức series tùy chỉnh

@recipe function f(
    ::Type{Val{:my_hviolin}}, x, y, z
)

# Series type seriestype := :violin
# Customization options framestyle := :grid label := false linewidth := 0 fillcolor := :purple fillalpha := 0.75 permute := (:x, :y) end
  • ::Type{Val{:my_hviolin}} định nghĩa my_hviolin là tên công thức series

  • x, y, z là dữ liệu series

  • seriestype cho biết loại series dùng trong công thức

  • Tham số tùy biến đặt bằng :=

Nhập môn Trực quan hóa Dữ liệu với Julia

Dùng công thức series tùy chỉnh

# Use recipe
plot(
    streaming.Fav_genre,
    streaming.Insomnia,
    # Specify series recipe
    seriestype=:my_hviolin,
)

xlabel!("Mất ngủ tự báo cáo")

Biểu đồ violin ngang: mức độ mất ngủ theo thể loại nhạc ưa thích.

Nhập môn Trực quan hóa Dữ liệu với Julia

Dùng công thức series tùy chỉnh

# Define my_hviolin function
@shorthands my_hviolin

# Use recipe my_hviolin( streaming.Fav_genre, streaming.Insomnia ) xlabel!("Mất ngủ tự báo cáo")

Biểu đồ violin ngang: mức độ mất ngủ theo thể loại nhạc ưa thích.

Nhập môn Trực quan hóa Dữ liệu với Julia

Cùng công thức, dữ liệu khác

my_hviolin(streaming.Fav_genre,
    streaming.OCD)
xlabel!("OCD tự báo cáo")

Biểu đồ violin ngang: mức độ OCD theo thể loại nhạc ưa thích.

my_hviolin(streaming.Fav_genre,
    streaming.Anxiety)
xlabel!("Lo âu tự báo cáo")

Biểu đồ violin ngang: mức độ lo âu theo thể loại nhạc ưa thích.

Nhập môn Trực quan hóa Dữ liệu với Julia

Công thức plot

  • Nhiều series

Lưới 1x2: biểu đồ violin và box của BPM theo thể loại ưa thích.

1 https://docs.juliaplots.org/latest/recipes/
Nhập môn Trực quan hóa Dữ liệu với Julia

Ayo berlatih!

Nhập môn Trực quan hóa Dữ liệu với Julia

Preparing Video For Download...