R တွင် ဇယားတစ်ခုတည်းတွင် စာကြောင်းများစွာ (ဒေတာစီးရီး) ကို မည်သို့ဆွဲမည်နည်း။


ဤသင်ခန်းစာတွင် လိုင်းများစွာ (ဥပမာ ဒေတာစီးရီး) ကို R တွင် ဇယားတစ်ခုတည်းတွင် မည်သို့ဆွဲရမည်ကို ရှင်းပြထားသည်။

ဂရပ်တစ်ခုတွင် လိုင်းများစွာကိုဆွဲရန်၊ ကျွန်ုပ်တို့သည် အခြေခံ R ကိုသုံးနိုင်သည် သို့မဟုတ် ggplot2 ကဲ့သို့ ပိုမိုဆန်းပြားသောပက်ကေ့ခ်ျတစ်ခုကို ထည့်သွင်းနိုင်သည်။

BaseR ကိုအသုံးပြုခြင်း။

ဤသည်မှာ Base R ကို အသုံးပြု၍ ဂရပ်တစ်ခုတွင် မျဉ်းများစွာကို ဆွဲချပုံ ဥပမာနှစ်ခုဖြစ်သည်။

ဥပမာ 1- Matplot ကို အသုံးပြုခြင်း။

သင့်တွင် ကြီးမားသော ဖော်မတ် ဒေတာအစုံရှိပါက၊ ဂရပ်တစ်ခုတွင် စာကြောင်းများစွာကို ချရန် လွယ်ကူသောနည်းလမ်းမှာ matplot ကို အသုံးပြုခြင်းဖြစ်သည်-

 #Create a fake dataset with 3 columns (ncol=3) composed of randomly generated
#numbers from a uniform distribution with minimum = 1 and maximum = 10
data <- matrix(runif(30,1,10), ncol=3)
data
        [,1] [,2] [,3]
#[1,] 5.371653 3.490919 3.953603
#[2,] 9.551883 2.681054 9.506765
#[3,] 3.525686 1.027758 8.059011
#[4,] 9.923080 1.337935 1.112361
#[5,] 7.273972 7.627546 1.174340
#[6,] 8.859109 3.778144 9.384526
#[7,] 9.614542 3.866029 7.301729
#[8,] 9.288085 5.804041 8.347907
#[9,] 1.696849 4.650687 7.220209
#[10,] 5.820941 4.799682 5.243663

#plot the three columns of the dataset as three lines and add a legend in
#the top right corner of the chart
matplot(data, type = "b",pch=1,col = 1:3)
legend("topright", legend = 1:3, col=1:3, pch=1)

ဤကုဒ်သည် အောက်ပါဂရပ်ကို ထုတ်ပေးသည်-

ဥပမာ 2- အမှတ်များနှင့် လိုင်းများကို အသုံးပြုခြင်း။

လိုင်းများစွာဆွဲရန် အခြားနည်းလမ်းမှာ တပ်ဆင်ထားသော R functions point() နှင့် လိုင်းများ() ကို အသုံးပြု၍ ၎င်းတို့ကို တစ်ကြိမ်လျှင် တစ်ခုဆွဲရန်ဖြစ်သည်။ အောက်ဖော်ပြပါ ကုဒ်သည် ဤချဉ်းကပ်မှု၏ ဥပမာကို ပြသည်-

 #generate an x-axis along with three data series
x <- c(1,2,3,4,5,6)
y1 <- c(2,4,7,9,12,19)
y2 <- c(1,5,9,8,9,13)
y3 <- c(3,6,12,14,17,15)

#plot the first data series using plot()
plot(x, y1, type="o", col="blue", pch="o", ylab="y", lty=1)

#add second data series to the same chart using points() and lines()
points(x, y2, col="red", pch="*")
lines(x, y2, col="red",lty=2)

#add third data series to the same chart using points() and lines()
points(x, y3, col="dark red",pch="+")
lines(x, y3, col="dark red", lty=3)

#add a legend in top left corner of chart at (x, y) coordinates = (1, 19)
legend(1,19,legend=c("y1","y2","y3"), col=c("blue","red","black"),
                                   pch=c("o","*","+"),lty=c(1,2,3), ncol=1)

ဤကုဒ်သည် အောက်ပါဂရပ်ကို ထုတ်ပေးသည်-

ggplot2 ကိုအသုံးပြုခြင်း။

ဤသည်မှာ ggplot2 ကို အသုံးပြု၍ ဂရပ်တစ်ခုတွင် မျဉ်းများစွာကို ဆွဲချနည်း ဥပမာတစ်ခုဖြစ်သည်။

 #install (if not already installed) and load ggplot2 package
if(!require(ggplot2)){install.packages(' ggplot2 ')}

#generate fake dataset with three columns 'x', 'value', and 'variable'
data <- data. frame (x=rep(1:5, 3),
                   value=sample(1:100, 15), 
                   variable=rep(paste0(' series ', 1:3), each=5))

#view dataset
head(data)
  x value variable
1 1 93 series1
2 2 64 series1
3 3 36 series1
4 4 17 series1
5 5 95 series1
6 1 80 series2

#plot all three series on the same chart using geom_line()
ggplot(data = data, aes(x=x, y=value)) + geom_line(aes(color=variable))

၎င်းသည် အောက်ပါဂရပ်ကို ထုတ်ပေးသည်-

ထပ်လောင်းအရင်းအမြစ်များ

အောက်ဖော်ပြပါ သင်ခန်းစာများသည် ggplot2 တွင် အခြားသော ဘုံကြံစည်မှု လုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-

ggplot2 တွင် ဒဏ္ဍာရီ အနေအထားကို ဘယ်လိုပြောင်းမလဲ။
ggplot2 တွင်ဒဏ္ဍာရီခေါင်းစဉ်ကိုဘယ်လိုပြောင်းမလဲ။
ggplot2 တွင် margin ကိုမည်သို့ပြောင်းလဲမည်နည်း။

မှတ်ချက်တစ်ခုထည့်ပါ။

သင့် email လိပ်စာကို ဖော်ပြမည် မဟုတ်ပါ။ လိုအပ်သော ကွက်လပ်များကို * ဖြင့်မှတ်သားထားသည်