Data <- read.csv("D:/05.csv")
Data
## Name Statistic Math Japanese Management Accounting
## 1 張青松 68 85 84 89 86
## 2 王奕翔 85 91 63 76 66
## 3 田新雨 74 74 61 80 69
## 4 徐麗娜 88 100 49 71 66
## 5 張志傑 63 82 89 78 80
## 6 趙穎睿 78 84 51 60 60
## 7 王智強 90 78 59 72 66
## 8 宋媛婷 80 100 53 73 70
## 9 袁四方 58 51 79 91 85
## 10 張建國 63 70 91 85 82
Statistic<- c(68,85,74,88,63,78,90,80,58,63)
Math <- c(85,91,74,100,82,84,78,100,51,70)
plot(Statistic,Math,
pch = 17,
col= "skyblue",
main ="班上的統計與數學成績",
xlab ="Statistic",
ylab ="Math")

hist(Math,
col= "lightyellow",
main ="班上的數學成績",
xlab ="數學成績",
ylab ="次數")

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

data2<- c(185,82,36,28,25)
labels <- c("娛樂休閒","知識閱讀","體育競技","科學創新","公益活動")
pie(data2,labels,main="大學生最喜歡參加的社團次數分配表",col=heat.colors(length(data2)))

# Load ggplot2
library(ggplot2)
# 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", width=0.2, fill="skyblue")

# Library
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ lubridate 1.9.4 ✔ tibble 3.2.1
## ✔ purrr 1.0.4 ✔ tidyr 1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# Create data3
data3 <- data.frame(
name = c("娛樂休閒", "知識閱讀", "體育競技", "科學創新", "公益活動"),
score = c(185, 82, 36, 28, 25)
)
# Plot
ggplot(data3, aes(x = name, y = score)) +
geom_segment(aes(x = name, xend = name, y = 0, yend = score)) +
geom_point(size = 5, color = "red", fill = alpha("orange", 0.3), alpha = 0.7, shape = 21, stroke = 2) +
labs(x = "項目", y = "分數", title = "各項活動得分分布") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))

Data <- read.csv("D:/05.csv")
Data
## Name Statistic Math Japanese Management Accounting
## 1 張青松 68 85 84 89 86
## 2 王奕翔 85 91 63 76 66
## 3 田新雨 74 74 61 80 69
## 4 徐麗娜 88 100 49 71 66
## 5 張志傑 63 82 89 78 80
## 6 趙穎睿 78 84 51 60 60
## 7 王智強 90 78 59 72 66
## 8 宋媛婷 80 100 53 73 70
## 9 袁四方 58 51 79 91 85
## 10 張建國 63 70 91 85 82
stem(Data$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 <- Data$Japanese
# 1. 平均數
mean_Jp <- mean(Japanese, na.rm = TRUE)
# 2. 中位數
median_Jp <- median(Japanese, na.rm = TRUE)
# 3. 眾數(自訂函數)
get_mode <- function(x) {
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
mode_Jp <- get_mode(Japanese)
# 4. 標準差
sd_Jp <- sd(Japanese, na.rm = TRUE)
# 5. 變異數
var_Jp <- var(Japanese, na.rm = TRUE)
# 6 & 7. 第一與第三四分位數
Q1_Jp <- quantile(Japanese, 1/4, na.rm = TRUE)
Q3_Jp <- quantile(Japanese, 3/4, na.rm = TRUE)