Ggplot2 တွင် pie charts ဖန်တီးနည်း (ဥပမာများနှင့်အတူ)


အဝိုင်းပုံဇယား သည် စက်ဝိုင်းပုံသဏ္ဍာန်ပုံစံဇယား အမျိုးအစားဖြစ်ပြီး တစ်ခုလုံး၏အချိုးအစားများကိုကိုယ်စားပြုရန် အချပ်များကို အသုံးပြုသည်။

ဤကျူတိုရီရယ်တွင် ggplot2 data visualization library ကို အသုံးပြု၍ R တွင် pie charts များ ဖန်တီးခြင်းနှင့် တည်းဖြတ်နည်းကို ရှင်းပြထားသည်။

အခြေခံ Pie Chart ဖန်တီးနည်း

အောက်ပါကုဒ်သည် ggplot2 ကို အသုံးပြု၍ ဒေတာအတွဲတစ်ခုအတွက် အခြေခံအဝိုင်းပုံဇယားကို ဖန်တီးနည်းကို ပြသသည်-

 library (ggplot2)

#create data frame
data <- data.frame(" category " = c('A', 'B', 'C', 'D'),
                   " amount " = c(25, 40, 27, 8))

#create pie chart
ggplot(data, aes (x="", y=amount, fill=category)) +
  geom_bar(stat=" identity ", width= 1 ) +
  coord_polar(" y ", start= 0 ) 

ggplot2 အဝိုင်းပုံဇယား

အဝိုင်းပုံဇယား၏အသွင်အပြင်ကို မည်သို့ပြောင်းလဲမည်နည်း။

ggplot2 ရှိ default pie chart သည် အလွန်ရုပ်ဆိုးသည်။ အသွင်အပြင်ကို မြှင့်တင်ရန် အလွယ်ဆုံးနည်းလမ်းမှာ နောက်ခံ၊ ဇယားကွက်နှင့် အညွှန်းများကို ဖယ်ရှားပေးသည့် theme_void() ကို အသုံးပြုရန်ဖြစ်သည်။

 ggplot(data, aes (x="", y=amount, fill=category)) +
  geom_bar(stat=" identity ", width= 1 ) +
  coord_polar(" y ", start= 0 ) +
  theme_void() 

အညွှန်းများမပါဘဲ ggplot2 အဝိုင်းပုံစံဇယား

အချပ်များအတွင်း အညွှန်းများထည့်ခြင်းဖြင့် ဇယား၏အသွင်အပြင်ကို ပိုမိုတိုးတက်ကောင်းမွန်အောင် လုပ်ဆောင်နိုင်သည်-

 ggplot(data, aes (x="", y=amount, fill=category)) +
  geom_bar(stat=" identity ", width= 1 ) +
  coord_polar(" y ", start= 0 ) +
  geom_text( aes (label = paste0(amount, " % ")), position = position_stack(vjust= 0.5 )) +
  labs(x = NULL, y = NULL, fill = NULL) 

စိတ်ကြိုက်အညွှန်းများဖြင့် ggplot2 ရှိ စက်ဝိုင်းပုံဇယား

Scale_fill_manual() အကြောင်းပြချက်ဖြင့် အချပ်များအတွက် အသုံးပြုရန် ကျွန်ုပ်တို့၏ကိုယ်ပိုင် ဆယ်ဂဏန်းဂဏန်းအရောင်များကို သတ်မှတ်ခြင်းဖြင့် ဇယားကို စိတ်ကြိုက်ပြင်ဆင်နိုင်သည်-

 ggplot(data, aes (x="", y=amount, fill=category)) +
  geom_bar(stat=" identity ", width= 1 ) +
  coord_polar(" y ", start= 0 ) +
  geom_text( aes (label = paste0(amount, " % ")), position = position_stack(vjust= 0.5 )) +
  labs(x = NULL, y = NULL, fill = NULL) +
  theme_classic() +
  theme(axis.line = element_blank(),
          axis.text = element_blank(),
          axis.ticks = element_blank()) +
  scale_fill_manual(values=c(" #FF5733 ", " #75FF33 ", " #33DBFF ", " #BD33FF ")) 

စက်ဝိုင်းဇယား ggplot2 လက်စွဲ ဖြည့်စွက်ရန် စကေး

အကြံပြုချက်- အတူတကွကောင်းမွန်သော hex အရောင်ကုဒ်များ ပေါင်းစပ်မှုများကို ရှာဖွေရန် ဤ hex အရောင်ရွေးချယ်မှုကို အသုံးပြုပါ။

ဘီယာထုတ်လုပ်သူ၏ အရောင်စကေး များထဲမှ တစ်ခုကို ရွေးချယ်ရုံဖြင့် အချပ်အရောင်များကို စိတ်ကြိုက်ပြင်ဆင်နိုင်သည်။ ဥပမာအားဖြင့်၊ ဤသည်မှာ “ အပြာရောင်” အရောင်စကေးနှင့်တူသည်-

 ggplot(data, aes (x="", y=amount, fill=category)) +
  geom_bar(stat=" identity ", width= 1 ) +
  coord_polar(" y ", start= 0 ) +
  geom_text( aes (label = paste0(amount, " % ")), position = position_stack(vjust= 0.5 )) +
  labs(x = NULL, y = NULL) +
  theme_classic() +
  theme(axis.line = element_blank(),
          axis.text = element_blank(),
          axis.ticks = element_blank()) +
  scale_fill_brewer(palette=" Blues ") 

ggplot2 တွင် စကေးဖြင့် ဘီယာချက်ပါ။

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

ggplot2 ကို အသုံးပြု၍ R တွင် အုပ်စုဖွဲ့ထားသော boxplot တစ်ခုကို ဖန်တီးနည်း
ggplot2 ကို အသုံးပြု၍ R တွင် အပူမြေပုံဖန်တီးနည်း
ggplot2 ကိုအသုံးပြု၍ R တွင် Gantt Chart ကိုဖန်တီးနည်း

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

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