用散佈圖視覺化插補後的數值
現在,讓我們重現第三章中用過、採用 geom_miss_point() 的其中一個圖。
為了達成這件事,我們需要把資料插補到低於原始資料範圍的位置。這是一種為了探索資料而進行的特殊插補。這種插補能示範我們需要練習的重點:如何追蹤遺漏值。要將資料插補到低於資料範圍的位置,我們會使用 impute_below_all() 函式。
本練習屬於課程
在 R 中處理遺漏值
練習說明
使用 oceanbuoys 資料:
- 使用
bind_shadow()、impute_below_all()和add_label_shadow()來進行插補並追蹤遺漏值。 - 在 x 與 y 軸上分別視覺化風速與氣溫的遺漏情形,並用
air_temp_c_NA為遺漏的氣溫數值著色。 - 在 x 與 y 軸上分別視覺化溼度與氣溫,並使用變數
any_missing為任何含有遺漏的案例著色。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Impute and track the missing values
ocean_imp_track <- bind_shadow(___) %>%
impute_below_all() %>%
add_label_shadow()
# Visualize the missingness in wind and air temperature,
# coloring missing air temp values with air_temp_c_NA
ggplot(___,
aes(x = ___, y = ___, color = ___)) +
geom_point()
# Visualize humidity and air temp, coloring any missing cases using the variable any_missing
ggplot(___,
aes(x = ___, y = ___, color = ___)) +
geom_point()