library(alr4)
library(ggplot2)
data<-UN11
x<-data$ppgdp
y<-data$fertility
#画散点图
ggplot(data=data,aes(x=ppgdp,y=fertility))+
geom_point()
#对数据取对数
ppgdp1=log(x)
fertility1=log(y)
data1=data.frame(ppgdp1,fertility1)
#画取自然对数后数据的散点图及回归直线
ggplot(data =data1,aes(x=ppgdp1,y=fertility1))+
geom_smooth(method = 'lm',se = FALSE)+
geom_point()
library(alr4)
library(ggplot2)
library(pastecs)
data<-wblake
summary(wblake) #描述性统计
myvars <- c("Age", "Length", "Scale")
stat.desc(data[myvars],basic = TRUE,desc=TRUE,norm=TRUE,p=0.95)
data<-data[order(data[,1],decreasing=F),] #按降序排列
#mytable<-with(data,table(Age)) #统计频数
data_mean<-aggregate(.~Age,data=data,mean)
data_sd<-aggregate(.~Age,data=data,sd)
x<-data$Age
y<-data$Length
ggplot(data=data,aes(x=Age,y=Length))+geom_point()
x<-data_mean$Age
y<-data_mean$Length
ggplot(data_mean, aes(x=Age,y=Length)) + geom_line() + geom_point(size=4, shape=20)
x<-data_sd$Age
y<-data_sd$Length
ggplot(data_sd, aes(x=Age,y=Length)) + geom_line() + geom_point(size=4, shape=20)
library(alr4)
library(ggplot2)
data<-Mitchell
p<-ggplot(data=data,aes(x=Month,y=Temp))+
geom_point()+coord_fixed(ratio=1/4) #把横坐标坐标拉宽
p
library(alr4)
library(ggplot2)
data<-Rateprof
quality<-data$quality
helpfulness<-data$helpfulness
clarity<-data$clarity
easiness<-data$easiness
raterInterest<-data$raterInterest
df<-data.frame(quality,helpfulness,clarity,easiness,raterInterest)
#变量矩阵散点图
pairs(df[1:5], main = "Average professor ratings",
pch = 21, bg = c("red", "green3", "blue")[unclass(df$Species)])
cor(df)