library(readr)
#讀取資料,命名為"money"-----
#一、下載money_management.csv,讀入Rstudio,命名為money
load("money_management.RData")
#二、快速檢視money的摘要資訊----
summary(money)
## id gender grade pocket_money savings household
## college: 66 女:116 一年級: 53 否:187 Min. : 0 否:209
## NDU :201 男:151 二年級:192 是: 80 1st Qu.: 2000 是: 58
## 三年級: 16 Median : 5000
## 四年級: 6 Mean : 5511
## 3rd Qu.: 8000
## Max. :30000
## keep_account
## 否:158
## 是:109
##
##
##
##
#三、不同年級(grade)人數的百分比為何?請依人數排列-----
prop.table(table(money$grade))*100
##
## 一年級 二年級 三年級 四年級
## 19.850187 71.910112 5.992509 2.247191
#四、不同年級(grade)的家用(household)差異為何?請以「長條圖」表示-----
p.s1 <- prop.table(table(money$household,money$grade))*100
p.s1 <- round(p.s1,2)
par(mfrow =c(1,2))
rownames(p.s1)
## [1] "否" "是"
label <- rownames(p.s1)
label
## [1] "否" "是"
barplot(p.s1, main = "大學生家用習慣",
beside = TRUE,
legend.text = label,
col =c("black","white"))
barplot(p.s1, main = "大學生家用習慣" ,
legend.text = label,
col =c("pink","white"))

dev.off()
## null device
## 1
#五、不同身份(id)的記帳(account)習慣差異為何?請以「圖餅圖」表示-----
p.t1 <- prop.table(table(money$id,money$keep_account))
college<- p.t1[1,]
NDU<- p.t1[2,]
college
## 否 是
## 0.1198502 0.1273408
NDU
## 否 是
## 0.4719101 0.2808989
pie(college, main ="college")
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '否' 發生錯誤:<e5>代替了 dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '否' 發生錯誤:<90>代替了 dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '否' 發生錯誤:<a6>代替了 dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : Unicode 字元 U+5426 不帶字型度量
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '是' 發生錯誤:<e6>代替了 dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '是' 發生錯誤:<98>代替了 dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '是' 發生錯誤:<af>代替了 dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : Unicode 字元 U+662f 不帶字型度量
pie(NDU, main ="NDU")
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '否' 發生錯誤:<e5>代替了 dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '否' 發生錯誤:<90>代替了 dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '否' 發生錯誤:<a6>代替了 dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : Unicode 字元 U+5426 不帶字型度量
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '是' 發生錯誤:<e6>代替了 dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '是' 發生錯誤:<98>代替了 dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '是' 發生錯誤:<af>代替了 dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : Unicode 字元 U+662f 不帶字型度量
pie_category <- colnames(p.t1)
college_label <- paste(pie_category, college,"%", sep = "")
college_label
## [1] "否0.119850187265918%" "是0.127340823970037%"
NDU_label <- paste(pie_category, NDU,"%", sep = "")
NDU_label
## [1] "否0.471910112359551%" "是0.280898876404494%"
pie(college, labels = college_label, main = "大學生記帳",sub = "by yun shiou")
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '否0.119850187265918%' 發生錯誤:<e5>代替了
## dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '否0.119850187265918%' 發生錯誤:<90>代替了
## dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '否0.119850187265918%' 發生錯誤:<a6>代替了
## dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : Unicode 字元 U+5426 不帶字型度量
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '是0.127340823970037%' 發生錯誤:<e6>代替了
## dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '是0.127340823970037%' 發生錯誤:<98>代替了
## dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : 'mbcsToSbcs' 裡轉換 '是0.127340823970037%' 發生錯誤:<af>代替了
## dot
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : Unicode 字元 U+662f 不帶字型度量
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<e5>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<a4>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<a7>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<e5>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<ad>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<b8>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<e7>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<94>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<9f>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<e8>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<a8>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<98>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<e5>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<b8>代替了 dot
## Warning in title(main = main, ...): 'mbcsToSbcs' 裡轉換 '大學生記帳'
## 發生錯誤:<b3>代替了 dot