Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###5.1###
- plot(x,y)
- plot(factor, y)
- barplot(y)
- ###5.2###
- data1 <- read.table("c:\\temp\\scatter1.txt",header=T) #CHANGE FILE#
- attach(data1)
- names(data1)
- plot(x1,y1,col="red")
- plot(x1,y1,col="red",xlab="Explanatory variable",ylab="Response variable")
- abline(lm(y1~x1))
- data2 <- read.table("c:\\temp\\scatter2.txt",header=T) #CHANGE FILE#
- attach(data2)
- names(data2)
- points(x2,y2,col="blue",pch=16)
- abline(lm(y2~x2))
- plot(c(x1,x2),c(y1,y2),xlab="Explanatory variable", ylab="Response variable",type="n")
- points(x1,y1,col="red")
- points(x2,y2,col="blue",pch=16)
- abline(lm(y1~x1))
- abline(lm(y2~x2))
- range(c(x1,x2))
- range(c(y1,y2))
- plot(c(x1,x2),c(y1,y2),xlim=c(0,100),ylim=c(0,70), xlab="Explanatory variable",ylab="Response variable",type="n")
- points(x1,y1,col="red")
- points(x2,y2,col="blue",pch=16)
- abline(lm(y1~x1))
- abline(lm(y2~x2))
- legend(locator(1),c("treatment","control"),pch=c(1,16), col=c("red","blue"))
- ##5.2.1##
- plot(0:10,0:10,xlim=c(0,32),ylim=c(0,40),type="n",xaxt="n",yaxt="n", xlab="",ylab="")
- x <- seq(1,31,2)
- s <- -16
- f <- -1 for (y in seq(2,40,2.5)) {
- s <- s+16
- f <- f+16 y2 <- rep(y,16) points(x,y2,pch=s:f,cex=0.7) text(x,y-1,as.character(s:f),cex=0.6) }
- ##5.2.2##
- plot(0:9,0:9,pch=16,type="n",xaxt="n",yaxt="n",ylab="col",xlab="bg")
- axis(1,at=1:8)
- axis(2,at=1:8)
- for (i in 1:8) points(1:8,rep(i,8),pch=c(21,22,24),bg=1:8,col=i)
- ##5.2.3##
- map.places <- read.csv("c:\\temp\\map.places.csv",header=T) #CHANGE FILE#
- attach(map.places)
- names(map.places)
- map.data <- read.csv("c:\\temp\\bowens.csv",header=T) #CHANGE FILE#
- attach(map.data)
- names(map.data)
- nn <- ifelse(north<60,north+100,north)
- windows(9,7)
- plot(c(20,100),c(60,110),type="n",xlab="",ylab="",xaxt="n", yaxt="n")
- for (i in 1:length(wanted)){
- ii <- which(place == as.character(wanted[i]))
- text(east[ii], nn[ii], as.character(place[ii]), cex = 0.6) }
- ##5.2.4##
- data <- read.table("c:\\temp\\sleep.txt",header=T) #CHANGE FILE#
- attach(data)
- plot(Days,Reaction)
- s <- as.numeric(factor(Subject))
- plot(Days,Reaction,type="n")
- for (k in 1:max(s)){
- x <- Days[s==k]
- y <- Reaction[s==k]
- lines(x,y,type="b",col="gray")
- }
- ##5.2.5##
- sym <- rep(c(21,22,24),c(7,7,4))
- bcol <- c(2:8,2:8,2:5)
- for (k in 1:max(s)){
- points(Days[s==k],Reaction[s==k],pch=sym[k],bg=bcol[k],col=1)
- }
- data <- read.table("c:\\temp\\pgr.txt",header=T) #CHANGE FILE#
- attach(data)
- names(data)
- plot(hay,pH)
- text(hay, pH, labels=round(FR, 2), pos=1, offset=0.5,cex=0.7)
- plot(hay,pH,pch=16,col=ifelse(FR>median(FR),"red","black"))
- legend(locator(1),c("FR>median","FR<=median"),pch=16,col=c("red","black"))
- ##5.2.6##
- smooth <- read.table("c:\\temp\\smoothing.txt",header=T) #CHANGE FILE#
- attach(smooth)
- names(smooth)
- plot(x,y,pch=16)
- sequence <- order(x)
- lines(x[sequence],y[sequence])
- plot(x,y,pch=16)
- lines(x,y)
- ##5.2.7##
- x<-0:10
- y<-0:10
- plot(x,y)
- lines(x,y,col="red")
- lines(x,y,col="blue",type="s")
- lines(x,y,col="green",type="S")
- ###5.3###
- plot(0:10,0:10,xlab="",ylab="",xaxt="n",yaxt="n",type="n")
- rect(6,6,9,9)
- ##5.3.1##
- corners <- function(){
- coos <- c(unlist(locator(1)),unlist(locator(1))) rect(coos[1],coos[2],coos[3],coos[4])
- }
- corners()
- arrows(1,1,3,8)
- arrows(1,9,5,9,code=3)
- arrows(4,1,4,6,code=3,angle=90)
- click.arrows <- function(){
- coos <- c(unlist(locator(1)),unlist(locator(1))) arrows(coos[1],coos[2],coos[3],coos[4])
- }
- click.arrows()
- locations <- locator(6)
- class(locations)
- locations
- polygon(locations,col="lavender")
- ##5.3.2##
- z <- seq(-3,3,0.01)
- pd <- dnorm(z)
- plot(z,pd,type="l")
- polygon(c(z[z<=-1],-1),c(pd[z<=-1],pd[z==-3]),col="red")
- ###5.4###
- curve(xˆ3-3*x, -2, 2)
- x <- seq(-2,2,0.01)
- y <- xˆ3-3*x
- plot(x,y,type="l")
- ##5.4.1##
- xv <- 0:100
- yA <- 482*xv*exp(-0.045*xv)
- yB <- 518*xv*exp(-0.055*xv)
- plot(c(xv,xv),c(yA,yB),xlab="stock",ylab="recruits",type="n")
- lines(xv,yA,lty=2,col="blue")
- lines(xv,yB,lty=1,col="red")
- info <- read.table("c:\\temp\\plotfit.txt",header=T) #CHANGE FILE#
- attach(info)
- names(info)
- points(x,y,pch=16)
- ##5.4.2##
- data <- read.table("c:\\temp\\jaws.txt",header=T) #CHANGE FILE#
- attach(data)
- names(data)
- par(mfrow=c(2,2))
- plot(age,bone,pch=16,main="lowess")
- lines(lowess(age,bone),col="red")
- plot(age,bone,pch=16,main="loess")
- model <- loess(bone~age)
- xv <- 0:50
- yv <- predict(model,data.frame(age=xv))
- lines(xv,yv,col="red")
- library(mgcv)
- plot(age,bone,pch=16,main="gam")
- model <- gam(bone~s(age))
- xv <- 0:50
- yv <- predict(model,list(age=xv))
- lines(xv,yv,col="red")
- plot(age,bone,pch=16,main="cubic polynomial"))
- model <- lm(bone~age+I(ageˆ2)+I(ageˆ3))
- xv <- 0:50
- yv <- predict(model,list(age=xv))
- lines(xv,yv,col="red")
- ###5.5###
- data <- read.table("c:\\temp\\pollute.txt",header=T) #CHANGE FILE#
- attach(data)
- par(mfrow=c(1,2))
- plot(Population,Pollution)
- plot(Temp,Pollution)
- windows(7,4)
- par(mfrow=c(1,2))
- plot(Population,Pollution)
- plot(Temp,Pollution)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement