weight <- c(55,60,70,75,75)
height <- c(155,160,170,175,175)
mean (weight)
## [1] 67
mean (height)
## [1] 167
median(weight)
## [1] 70
median(height)
## [1] 170
min(weight)
## [1] 55
min(height)
## [1] 155
max(weight)
## [1] 75
max(height)
## [1] 175
as.numeric(names(table(weight)))[which.max(table(weight))]
## [1] 75
as.numeric(names(table(height)))[which.max(table(height))]
## [1] 175
sd(weight) #標準差
## [1] 9.082951
sd(height) #標準差
## [1] 9.082951
var(weight) #變異數\
## [1] 82.5
var(height) #變異數
## [1] 82.5
plot(weight, height,
pch = 17,
col= "darkblue",
main ="班上的體重與身高",
xlab ="體重",
ylab ="身高")

hist(weight,
col= "black",
main ="班上的體重與身高",
xlab ="體重",
ylab ="生高")

# Load ggplot2
library(ggplot2)
# Load ggplot2
library(ggplot2)
# Create data
data <- data.frame(
name=c("王曉明","B","C","D","E","F") ,
value=c(50,55,63,55,67,43)
)
# Barplot
ggplot(data, aes(x=name, y=value)) +
geom_bar(stat = "identity", width=0.2, fill="skyblue")

data<- c(50,23,35,48)
labels <- c("英文系","法文系","德文","翻譯")
pie(data,labels,main ="學生的比例", col=rainbow(length(data)))
