BaşlayınÜcretsiz Başlayın

Improve pie chart

The pie chart is a very common way to represent the distribution of a single categorical variable, but they can be more difficult to interpret than bar charts.

This is a pie chart of a dataset called pies that contains the favorite pie flavors of 98 people. Improve the representation of these data by constructing a bar chart that is ordered in descending order of count.

Bu egzersiz

Exploratory Data Analysis in R

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Use the code provided to reorder the levels of flavor so that they're in descending order by count.
  • Create a bar chart of flavor and orient the labels vertically so that they're easier to read. The default coloring may look drab by comparison, so change the fill of the bars to "chartreuse".

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Put levels of flavor in descending order
lev <- c("apple", "key lime", "boston creme", "blueberry", "cherry", "pumpkin", "strawberry")
pies$flavor <- factor(pies$flavor, levels = lev)

# Create bar chart of flavor
ggplot(___, aes(x = ___)) + 
  geom_bar(fill = ___) + 
  theme(axis.text.x = element_text(angle = 90))
Kodu Düzenle ve Çalıştır