R တွင် များစွာသော histograms များကို မည်သို့ဆွဲမည်နည်း (ဥပမာများဖြင့်)
အခြေခံ R ရှိ တူညီသောကားချပ်ပေါ်တွင် များစွာသော histograms များကို ချရန် အောက်ပါ syntax ကို အသုံးပြုနိုင်သည်။
hist(data1, col=' red ') hist(data2, col=' blue ', add= TRUE )
ggplot2 တွင် များစွာသော histograms များကို ချရန် အောက်ပါ syntax ကိုသုံးနိုင်သည်။
ggplot(df, aes(x = x_var, fill = grouping_var)) + geom_histogram(position = ' identity ', alpha = 0.4 )
အောက်ဖော်ပြပါ ဥပမာများသည် ဤနည်းလမ်းတစ်ခုစီကို လက်တွေ့အသုံးချနည်းကို ပြသထားသည်။
နည်းလမ်း 1- အခြေခံ R တွင် histogram များစွာဆွဲပါ။
အောက်ဖော်ပြပါ ကုဒ်သည် အခြေခံ R ရှိ ကွက်ကွက်တစ်ခုတွင် အများအပြား ဟီစတိုဂရမ်များစွာကို ပုံဖော်နည်းကို ပြသသည်-
#make this example reproducible
set. seeds (1)
#define data
x1 = rnorm(1000, mean=0.8, sd=0.2)
x2 = rnorm(1000, mean=0.4, sd=0.1)
#plot two histograms in same graph
hist(x1, col=' red ', xlim=c(0, 1.5), main=' Multiple Histograms ', xlab=' x ')
hist(x2, col=' green ', add= TRUE )
#add legend
legend(' topright ', c(' x1 variable ', ' x2 variable '), fill=c(' red ', ' green '))
နည်းလမ်း 2- ggplot2 တွင် Multiple Histograms ကိုဆွဲပါ။
အောက်ပါကုဒ်သည် ggplot2 ကို အသုံးပြု၍ R တွင်ကွက်ကွက်တစ်ခုတွင် များပြားသော histogram များကို မည်သို့ဆွဲရမည်ကို ပြသသည် ။
library (ggplot2)
#make this example reproducible
set. seeds (1)
#create data frame
df <- data. frame (var = c(rep(' x1 ', 1000), rep(' x2 ', 1000) ),
value = c(rnorm(1000, mean=0.8, sd=0.1),
rnorm(1000, mean=0.4, sd=0.1)))
#view first six rows of data frame
head(df)
var value
1 x1 0.7373546
2 x1 0.8183643
3 x1 0.7164371
4x1 0.9595281
5 x1 0.8329508
6 x1 0.7179532
#plot multiple histograms
ggplot(df, aes(x=value, fill=var)) +
geom_histogram(color=' #e9ecef ', alpha=0.6, position=' identity ')
scale_fill_manual() လုပ်ဆောင်ချက်ကို အသုံးပြု၍ histogram များ၏ အရောင်များကို လျင်မြန်စွာ ပြောင်းလဲနိုင်သည်-
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် R တွင် အခြားဘုံဂရပ်များကို ဖန်တီးနည်းကို ရှင်းပြသည်-
R တွင် နှိုင်းရကြိမ်နှုန်း ဟီစတိုဂရမ် ဖန်တီးနည်း
R တွင် ဂရပ်တစ်ခုတွင် ကွက်ကွက်များစွာကို မည်သို့ဆွဲမည်နည်း။
R ဖြင့် ဂရပ်တစ်ခုတွင် စာကြောင်းများစွာကို ဘယ်လိုဆွဲမလဲ။