<jupyter_start><jupyter_text>資料介紹> Students and faculty at Cornell College in Mount Vernon, Iowa, collected data over many years at the hawk blind at Lake MacBride near Iowa City, Iowa. The data set that we are analyzing here is a subset of the original data set, using only those species for which there were more than 10 observations. Data were collected on random samples of three different species of hawks: Red-tailed, Sharp-shinned, and Cooper's hawks. 來源文件https://vincentarelbundock.github.io/Rdatasets/doc/Stat2Data/Hawks.html 使用欄位| 欄位 | 說明 || -- | -- | | Year |  Year: 1992-2003 || Species |   CH=Cooper's, RT=Red-tailed, SS=Sharp-Shinned || Age |   A=Adult or I=Imature || Sex |   F=Female or M=Male || Wing |  Length (in mm) of primary wing feather from tip to wrist it attaches to || Weight |  Body weight (in gm) || Culmen |  Length (in mm) of the upper bill from the tip to where it bumps into the fleshy part of the bird || Hallux |  Length (in mm) of the killing talon || Tail |  Measurement (in mm) related to the length of the tail (invented at the MacBride Raptor Center) | 隼種類| Cooper | Red-tailed | Sharp-Shinned || -- | -- | -- || ![cooper](https://i.imgur.com/yElU0mT.jpeg) | ![red-tailed](https://i.imgur.com/stDkmjH.jpeg) | ![Sharp-Shinned](https://i.imgur.com/NXFkDbt.jpeg)|  資料預覽 載入資料<jupyter_code>install.packages("data.table")
library(data.table)
# 從網路位置下載資料
hawks <- fread("https://vincentarelbundock.github.io/Rdatasets/csv/Stat2Data/Hawks.csv", 
                select = c('Species', 'Age', 'Sex', 'Wing', 'Hallux', 'Weight', 'Tail', 'Year'), data.table = F, stringsAsFactors = T)

# 空字串應為 NA 值
hawks[hawks == ""] <- NA

# 僅取部分資料顯示
head(hawks, 10)<jupyter_output><empty_output><jupyter_text>資料概覽<jupyter_code>summary(hawks)<jupyter_output><empty_output><jupyter_text>調整資料內容<jupyter_code># 將年份轉為類別資料
hawks$Year <- as.factor(hawks$Year)

# 移除空白的 level
hawks$Sex <- droplevels(hawks$Sex)
summary(hawks)<jupyter_output><empty_output><jupyter_text>資料分布<jupyter_code>install.packages("patchwork")
library(patchwork)
library(ggplot2)
library(scales)
options(repr.plot.res = 160)

blank_theme <- theme_minimal() + theme(
  axis.title.x = element_blank(),
  axis.title.y = element_blank(),
  panel.border = element_blank(),
  panel.grid=element_blank(),
  axis.ticks = element_blank(),
)

draw_pie <- function(d, title){
    df <- as.data.frame(table(d, useNA = "ifany"), row.names = NULL)
    colnames(df) <- c("var", "freq")
    
    value <- df$freq
    group <- df$var

    pie <- ggplot(df, aes(x="", y=value, fill=group))+ geom_bar(width = 1, stat = "identity") + coord_polar(theta = "y")
    pie + labs(title=title) + theme_gray() + blank_theme
}

draw_density <- function(x, title){
    ggplot(hawks, aes(x=x)) + geom_density() + labs(title=title) + scale_y_continuous(labels = percent, name = "percent") + theme_gray()
}
g0 <- draw_pie(hawks$Sex, "Sex")
g1 <- draw_pie(hawks$Species, "Species")
g2 <- draw_pie(hawks$Year, "Year")

g0 + g1 + g2
g3 <- draw_density(hawks$Wing, "Wing")
g4 <- draw_density(hawks$Hallux, "Hallux")
g5 <- draw_density(hawks$Weight, "Weight")
g6 <- draw_density(hawks$Tail, "Tail")

g3 + g4 + g5 + g6 + plot_layout(ncol = 4)<jupyter_output>Warning message:
“Removed 1 rows containing non-finite values (stat_density).”
Warning message:
“Removed 6 rows containing non-finite values (stat_density).”
Warning message:
“Removed 10 rows containing non-finite values (stat_density).”
{'fraction_non_alphanumeric': 0.14818049490538573, 'fraction_numerical': 0.011353711790393014, 'mean_word_length': 4.784511784511785, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 17, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '115624', 'license': 'MIT', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1322, 'n_words': 316, 'path': '1092_10030009/20210321.ipynb', 'repo_name': 'lisez/tmu', 'size': '3435'}