Ggplot2 တွင် violin plot ဖန်တီးနည်း (ဥပမာများနှင့်အတူ)
ggplot2 တွင် တယောကွက်ဖန်တီးရန် အောက်ပါနည်းလမ်းများကို သင်အသုံးပြုနိုင်ပါသည်။
နည်းလမ်း 1- အုပ်စုအလိုက် တယောကွက်များ ဖန်တီးပါ။
ggplot(df, aes(x=group_var, y=values_var, fill=group_var)) +
geom_violin() +
နည်းလမ်း 2- အုပ်စုလိုက် အလျားလိုက် တယောလမ်းကြောင်းများ ဖန်တီးပါ။
ggplot(df, aes(x=group_var, y=values_var, fill=group_var)) +
geom_violin() +
coordinate_flip()
နည်းလမ်း 3- အုပ်စုအလိုက် တယောကွက်များကို ဖန်တီးပြီး အလယ်တန်းတန်ဖိုးကို ပြသပါ။
ggplot(df, aes(x=group_var, y=values_var, fill=group_var)) +
geom_violin() +
stat_summary(fun=median, geom=' point ', size= 2 )
အောက်ဖော်ပြပါ ဥပမာများသည် R ရှိ ဒေတာဘောင်ဖြင့် လက်တွေ့တွင် နည်းလမ်းတစ်ခုစီကို အသုံးပြုနည်းကို ပြသသည်-
#make this example reproducible
set. seeds (1)
#create data frame
df <- data. frame (team=rep(c(' A ', ' B ', ' C '), each= 100 ),
points=c(rnorm(100, mean=10),
rnorm(100, mean=15),
rnorm(100, mean=20)))
#view head of data frame
head(df)
team points
1 A 9.373546
2 A 10.183643
3 A 9.164371
4 A 11.595281
5 A 10.329508
6 A 9.179532
မှတ်ချက် – ဤဥပမာသည် မျိုးပွားနိုင်စေရန် သေချာစေရန် set.seed() လုပ်ဆောင်ချက်ကို အသုံးပြုထားပါသည်။
ဥပမာ 1- အုပ်စုအလိုက် တယောခြေရာခံများကို ဖန်တီးပါ။
team variable ဖြင့် အုပ်စုဖွဲ့ထားသော အမှတ်များ ကွဲပြားမှုကို ပြသသည့် တယောကွက်များကို ဖန်တီးရန် အောက်ပါ syntax ကို အသုံးပြုနိုင်ပါသည်။
library (ggplot2)
#create violin plot to visualize distribution of points by team
ggplot(df, aes(x=team, y=points, fill=team)) +
geom_violin()
x-axis သည် အဖွဲ့တစ်ခုစီကိုပြသပြီး y-axis သည် အဖွဲ့တစ်ခုစီမှရမှတ်များခွဲဝေမှုကိုပြသသည်။
ဥပမာ 2- အုပ်စုအလိုက် တယောခြေရာများကို ဖန်တီးပါ။
team variable ဖြင့် အုပ်စုဖွဲ့ထားသော အမှတ်များ ကွဲပြားမှုကို ပြသသည့် အလျားလိုက် တယောကွက်များ ဖန်တီးရန်၊ coord_flip() လုပ်ဆောင်ချက်ကို ရိုးရှင်းစွာ ထည့်ပါ။
library (ggplot2)
#create horizontal violin plots to visualize distribution of points by team
ggplot(df, aes(x=team, y=points, fill=team)) +
geom_violin() +
coordinate_flip()
y-axis သည် အဖွဲ့တစ်ခုစီကိုပြသပြီး x-axis သည် အသင်းတစ်ခုစီမှရမှတ်များခွဲဝေမှုကိုပြသသည်။
ဥပမာ 3- တယောကွက်များကို အုပ်စုအလိုက် ဖန်တီးပြီး ပျမ်းမျှတန်ဖိုးကို ပြသပါ။
အောက်ဖော်ပြပါ ကုဒ်သည် စက်ဝိုင်းတစ်ခုမှ ကိုယ်စားပြုသော အမှတ်တန်ဖိုးများဖြင့် အဖွဲ့ ကွဲကွဲပြားပြားဖြင့် အုပ်စုဖွဲ့ထားသော အမှတ်များ ကွဲပြားမှုကို ပြသသည့် တယောကွက်များ ဖန်တီးနည်းကို သရုပ်ပြသည်-
library (ggplot2)
#create violin plots and display median points value as circle
ggplot(df, aes(x=team, y=points, fill=team)) +
geom_violin() +
stat_summary(fun=median, geom=' point ', size= 2 )
အဖွဲ့တစ်ခုစီအတွက် ပျမ်းမျှအမှတ်တန်ဖိုးကို fiddle ကွက်တစ်ခုစီရှိ စက်ဝိုင်းငယ်ဖြင့် ကိုယ်စားပြုသည်။
မှတ်ချက် – စက်ဝိုင်း၏အရွယ်အစားကို တိုးမြှင့်ရန်၊ stat_summary() လုပ်ဆောင်ချက်ရှိ အရွယ်အစား အငြင်းအခုံတန်ဖိုးကို ရိုးရိုးရှင်းရှင်း တိုးမြှင့်ပါ။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် ggplot2 တွင် အခြားဘုံအလုပ်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
ggplot2 မှာ ဖောင့်အရွယ်အစားကို ဘယ်လိုပြောင်းမလဲ။
ggplot2 တွင်ဒဏ္ဍာရီကိုမည်သို့ဖယ်ရှားနည်း
ggplot2 တွင် ဝင်ရိုးတံဆိပ်များကို လှည့်နည်း