Ggplot2 ကိုအသုံးပြု၍ r တွင် gantt chart ကိုဖန်တီးနည်း


Gantt ဇယား သည် အမျိုးမျိုးသော ပွဲများ၏ အစနှင့် အဆုံးအချိန်များကို ပြသသည့် ဇယားအမျိုးအစားတစ်ခုဖြစ်သည်။

ဤသင်ခန်းစာသည် ggplot2 အထုပ်ကို အသုံးပြု၍ R တွင် Gantt ဇယားကိုဖန်တီးနည်းကို ရှင်းပြထားသည်။

ggplot2 ကို အသုံးပြု၍ R တွင် Gantt ဇယားကိုဖန်တီးခြင်း။

စတိုးဆိုင်တစ်ခုတွင် မတူညီသော အလုပ်သမားအဆိုင်း လေးခု၏ အစနှင့် ကုန်ဆုံးချိန်များကို ပြသသည့် အောက်ပါဒေတာအစုံရှိသည် ဆိုကြပါစို့။

 #create data frame
data <- data.frame(name = c('Bob', 'Greg', 'Mike', 'Andy'), 
start = c(4, 7, 12, 16),
end = c(12, 11, 8, 22),
shift_type = c('early', 'mid_day', 'mid_day', 'late')
)
data

# name start end shift_type
#1 Bob 4 12 early
#2 Greg 7 11 mid_day
#3 Mike 12 8 mid_day
#4 Andy 16 22 late

အလုပ်သမားတစ်ဦးစီ၏ အစနှင့် ပြီးဆုံးချိန်များကို မြင်သာစေသည့် ggplot2 ကို အသုံးပြု၍ Gantt ဇယားကို ဖန်တီးရန်အတွက်၊ ကျွန်ုပ်တို့သည် အောက်ပါကုဒ်ကို အသုံးပြုနိုင်ပါသည်။

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

#create gantt chart that visualizes start and end time for each worker
ggplot(data, aes(x=start, xend=end, y=name, yend=name, color=shift_type)) +
  geom_segment()

၎င်းသည် အောက်ပါ Gantt ဇယားကို ထုတ်လုပ်သည်။

အပြင်အဆင်ကို ပြုပြင်ပြောင်းလဲမှုအနည်းငယ်ဖြင့်၊ ကျွန်ုပ်တို့သည် ဤ Gantt ဇယားကို ပိုမိုကြည့်ကောင်းအောင် ပြုလုပ်နိုင်သည်-

 ggplot(data, aes(x=start, xend=end, y=name, yend=name, color=shift_type)) +
theme_bw()+ #use ggplot theme with black gridlines and white background
geom_segment(size=8) + #increase line width of segments in the chart
labs(title='Worker Schedule', x='Time', y='Worker Name')

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

ထို့အပြင်၊ သင်သည် ဇယားတွင်အသုံးပြုရန် အတိအကျအရောင်များကို သတ်မှတ်လိုပါက အောက်ပါကုဒ်ကို အသုံးပြုနိုင်သည်။

 ggplot(data, aes(x=start, xend=end, y=name, yend=name, color=shift_type)) +
  theme_bw()+ #use ggplot theme with black gridlines and white background
  geom_segment(size=8) + #increase line width of segments in the chart
  labs(title='Worker Schedule', x='Time', y='Worker Name') +
  scale_color_manual(values = c('pink', 'purple', 'blue'))

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

စိတ်ကြိုက် အပြင်အဆင်များကို သုံးပါ။

ggthemes ဒစ်ဂျစ် တိုက်မှ စိတ်ကြိုက် အပြင်အဆင်များကို အသုံးပြု၍ ကျွန်ုပ်တို့ ရှေ့ဆက်သွားနိုင်ပါသည်။

ဥပမာအားဖြင့်၊ Wall Street Journal မှုတ်သွင်းထားသော အပြင်အဆင်ကို အသုံးပြုသည့် Gantt ဇယားကို ဖန်တီးနိုင်သည်-

 #load ggthemes library
library(ggthemes)

#create scatterplot with Wall Street Journal theme
ggplot(data, aes(x=start, xend=end, y=name, yend=name, color=shift_type)) +
  theme_bw()+
  geom_segment(size=8) +
  labs(title='Worker Schedule', x='Time', y='Worker Name') +
  scale_color_manual(values = c('pink', 'purple', 'blue')) +
  theme_wsj() + 
  theme(axis.title = element_text())

သို့မဟုတ် The Economist မှ လှုံ့ဆော်ပေးသော ဆောင်ပုဒ်ကို အသုံးပြုနိုင်သည်။

 ggplot(data, aes(x=start, xend=end, y=name, yend=name, color=shift_type)) +
  theme_bw()+
  geom_segment(size=8) +
  labs(title='Worker Schedule', x='Time', y='Worker Name') +
  scale_color_manual(values = c('pink', 'purple', 'blue')) +
  theme_economist() + 
  theme(axis.title = element_text())

သို့မဟုတ် Five thirty Eight မှုတ်သွင်းထားသော theme ဖြစ်နိုင်သည်-

 ggplot(data, aes(x=start, xend=end, y=name, yend=name, color=shift_type)) +
  theme_bw()+
  geom_segment(size=8) +
  labs(title='Worker Schedule', x='Time', y='Worker Name') +
  scale_color_manual(values = c('pink', 'purple', 'blue')) +
  theme_fivethirtyeight() + 
  theme(axis.title = element_text())

ggthemes ဒစ် ဂျစ်တိုက်တွင်ရရှိနိုင်သည့် အပြင်အဆင်များစာရင်းအပြည့်အစုံအတွက်၊ စာရွက်စာတမ်းစာမျက်နှာကို ကြည့်ပါ။

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

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