we <- c(68,85,74,88,63,78,90,80,58,63)
we2 <- c(85,91,74,100,82,84,78,100,51,70)
plot(we,we2,
pch = 17,
col= "skyblue",
main ="班上的統計與數學",
xlab ="數學成績",
ylab ="統計成績")

hist(we,
col= "lightyellow",
main ="班上的統計成績的直方圖",
xlab ="統計成績",
ylab ="次數")

hist(we,
col= "lightyellow",
main ="大學生最喜歡參加的社團的次數分配表",
xlab ="名稱",
ylab ="次數")

# Load ggplot2
library(ggplot2)
# Create data
data <- data.frame(
name=c("娛樂休閒","知識閱讀","體育競技","科學創新","公益活動") ,
value=c(185,82,36,28,25)
)
# Barplot
ggplot(data, aes(x=name, y=value)) +
geom_bar(stat = "identity")

mean(we)
## [1] 74.7
## [1] 67
data<- c(185,82,36,28,25)
labels <- c("娛樂休閒","知識閱讀","體育競技","科學創新","公益活動")
pie(data,labels,main ="學生的比例", col=heat.colors(length(data)))

data2 <- data.frame(
x=c("娛樂休閒","知識閱讀","體育競賽","科學創新","公益活動"),
y=c(185,82,36,28,25))
ggplot(data2, aes(x=x, y=y)) +
geom_segment( aes(x=x, xend=x, y=0, yend=y)) +
geom_point( size=5, color="red",
fill=alpha("orange",0.3), alpha=0.7, shape=21, stroke=2)

japanese <- c(84,63,61,49,89,51,59,53,79,91)
stem(japanese)
##
## The decimal point is 1 digit(s) to the right of the |
##
## 4 | 9
## 5 | 139
## 6 | 13
## 7 | 9
## 8 | 49
## 9 | 1
# 資料
japanese <- c(84, 63, 61, 49, 89, 51, 59, 53, 79, 91)
# 1. 平均數
mean_j <- mean(japanese)
# 2. 中位數
median_j <- median(japanese)
# 3. 眾數函數
get_mode <- function(x) {
ux <- unique(x)
tab <- tabulate(match(x, ux))
modes <- ux[tab == max(tab)]
return(modes)
}
mode_j <- get_mode(japanese)
# 4. 標準差
sd_j <- sd(japanese)
# 5. 變異數
var_j <- var(japanese)
# 6. 第一四分位數 Q1
q1_j <- quantile(japanese, 0.25)
# 7. 第三四分位數 Q3
q3_j <- quantile(japanese, 0.75)
# 顯示結果
cat("Mean:", mean_j, "\n")
## Mean: 67.9
## Mean: 67.9
cat("Median:", median_j, "\n")
## Median: 62
## Median: 62
cat("Mode(s):", mode_j, "\n")
## Mode(s): 84 63 61 49 89 51 59 53 79 91
## Mode(s): 84 63 61 49 89 51 59 53 79 91
cat("Standard Deviation:", sd_j, "\n")
## Standard Deviation: 16.25115
## Standard Deviation: 16.25115
cat("Variance:", var_j, "\n")
## Variance: 264.1
## Variance: 264.1
cat("Q1 (1st Quartile):", q1_j, "\n")
## Q1 (1st Quartile): 54.5
## Q1 (1st Quartile): 54.5
cat("Q3 (3rd Quartile):", q3_j, "\n")
## Q3 (3rd Quartile): 82.75
## Q3 (3rd Quartile): 82.75