開始使用免費開始

基礎 ridgeline 圖

以下提供的程式碼會繪製 ridgeline 圖,呈現一週中各天被攔查的駕駛超速百分比分佈。

請修改程式碼:將核心寬度(bandwidth)設為指定數值、調整 x 軸範圍以去除長尾,並加入 subtitle,告知讀者你所使用的 bandwidth。

本練習屬於課程

R 視覺化最佳實務

檢視課程

練習說明

  • geom_density_ridges()bandwidth 改為 3.5。
  • 將 x 尺度的 limits 設為從 0150
  • 為圖加上副標題 'Gaussian kernel SD = 3.5'

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

library(ggridges)

md_speeding %>% 
    mutate(day_of_week = factor(day_of_week, levels = c("Mon","Tues","Wed","Thu","Fri","Sat","Sun") )) %>% 
    ggplot(aes( x = percentage_over_limit, y = day_of_week)) + 
    # Set bandwidth to 3.5
    geom_density_ridges() +
    # add limits of 0 to 150 to x-scale
    scale_x_continuous() 
    # provide subtitle with bandwidth
    
編輯並執行程式碼