'柱状图'
beer = scan()
barplot(table(beer)/length(beer),col='lightblue')
beer.counts = table(beer)
'饼状图'
names(beer.counts) = c('Domestic\n can','Domestic\n bottle','Microbrew','Import')
pie(beer.counts,col = c('purple','red','blue','green2'))
'直方图'
x = scan()
hist(x,probability = TRUE)
'箱线图'
x = scan()
boxplot(x,horizontal = TRUE)
growth=c(75,72,73,61,67,64,62,63)
sugar=c("C","C","C","E","E","E","S","S")
fly=data.frame(growth=growth, sugar=sugar)
boxplot(growth ~ sugar,
data=fly,
xlab="Sugar typey",ylab="Growth",
col="bisque",
range=0) # range:数值,默认为1.5,表示触须的范围,即range * (Q3 - Q1)
title(main="Growth against sugar type",font.main= 4)
'散点图'
plot(dist~speed,data = cars)
plot(dist ~speed,data= cars,xlab='Speed',ylab="Distance",col="blue")
title(main="Scatter plot with best-fit line",font.main= 4)
abline(lm(dist ~ speed,data= cars),col= "red") # 直线拟合
plot(dist~speed,data= cars,
pch= 19, # 点的形状
xlim= c(0,25),ylim= c(-20,120), # x,y轴坐标轴范围
cex= 1) # 点的大小
abline(lm(dist ~ speed,data= cars)) # lm表示拟合
title(main="Scatter plot with altered y-axis")
R语言——第六课
最新推荐文章于 2024-08-13 20:31:51 发布