這份作業希望你可以利用視覺化的文法(grammar of graphics) 呈現結果。
這次的作業使用我自己抓的 PTT 棒球版資料,有興趣的話可以點進完整的文章 誰是中職人氣王?哪隊球迷愛出征?PTT資料全解析 。
因為重點是練習畫圖,所以我都先畫好基本的圖,請你改成範例的樣子。
### 這邊不要動
library(tidyverse)
library(lubridate)
library(ggrepel)
<- read_rds("data/Lab07/df_hot_agg.rds")
df_hot_agg # df_hot_agg <- rea_csv("data/Lab07/df_hot_agg.csv")
<- read_rds("data/Lab07/df_main_type_n_big.rds")
df_main_type_n_big # df_main_type_n_big <- read_csv("data/Lab07/df_main_type_n_big.csv")
<- read_rds("data/Lab07/df_main_date_agg_four.rds")
df_main_date_agg_four # df_main_date_agg_four <- read_csv("data/Lab07/df_main_date_agg_four.csv")
<- read_rds("data/Lab07/df_push_agg_join_agg.rds")
df_push_agg_join_agg # df_push_agg_join_agg <- read_csv("data/Lab07/df_push_agg_join_agg.csv")
= c("Elephants"="中信兄弟","Guardians"="富邦悍將","Lions"="統一獅","Monkeys"="樂天桃猿","Dragons"="味全龍")
value_team_pair = c("Elephants"="#FAB419","Guardians"="#004D9A","Monkeys"="#990036","Lions"="#FF8000","Dragons"="#D71010")
value_team_color_english = c("Elephants"="爪爪","Guardians"="邦邦","Lions"="喵喵","Monkeys"="吱吱") value_team_pair_short
### raw
%>%
df_hot_agg ggplot(aes(x = board, y = value)) +
geom_col() +
facet_wrap(type ~ .)
### 熱門度統計: 文章數、推文數
::include_graphics('data/Lab07/plot_popularity_article.png')
knitr# plot_popularity_article %>%
# ggsave(filename = str_c("photo/","plot_popularity_article_test", ".png"), dpi = 600, height = 8, width = 12)
### raw
%>%
df_main_type_n_big ggplot(aes(x = board, y = per, alpha = type)) +
geom_col()
### 各板的發文類型有差嗎
::include_graphics('data/Lab07/plot_type.png') knitr
### raw
%>%
df_main_date_agg_four ggplot(aes(x = date, y = n_article)) +
geom_line() +
facet_wrap(board ~ .)
### 發生大事件
::include_graphics('data/Lab07/plot_date_all.png') knitr
### raw
%>%
df_push_agg_join_agg ggplot(aes(x = name, y = n)) +
geom_col() +
facet_wrap(board ~ ., scales = "free") +
coord_flip()
### 都在討論誰
::include_graphics('data/Lab07/plot_player_self.png') knitr