बेसिक स्टैक्ड बार्स
पिछले अभ्यासों में जब हमने pie और waffle charts बनाए थे, तब हमने सभी वर्षों के डेटा को एक साथ देखा था.
अब हम इन पैटर्न्स को समय के साथ देखना चाहते हैं। इसके लिए हम एक stacked bar chart बनाएँगे, जहाँ x-axis पर observation का year होगा। जैसे पहले pie chart में किया था, हम डेटा को सिर्फ measles, mumps, और other तक सरल करेंगे.
क्या इस तरह visualize करने के बाद आपको डेटा में कुछ असामान्य दिखता है?
यह अभ्यास पाठ्यक्रम का हिस्सा है
R में Visualization की Best Practices
अभ्यास निर्देश
aes()कॉल में year को x-axis से मैप करें.geom_col()मेंpositionआर्ग्युमेंट को बदलकर बार्स को पूरी y-axis भरने दें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
disease_counts <- who_disease %>%
mutate(disease = ifelse(disease %in% c('measles', 'mumps'), disease, 'other')) %>%
group_by(disease, year) %>% # note the addition of year to the grouping.
summarise(total_cases = sum(cases))
# add the mapping of year to the x axis.
ggplot(disease_counts, aes(___, y = total_cases, fill = disease)) +
# Change the position argument to make bars full height
geom_col(___)