{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE)

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

{r cars} summary(cars)

Including Plots

You can also embed plots, for example:

{r pressure, echo=FALSE} plot(pressure)

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

x<- 1:10

[1] 1 2 3 4 5 6 7 8 9 10 y<-c(11,12,9,7,5,8,4,4,5,3)

plot(x,y)

plot(x,y,xlab=“Explanatory variable”)

plot(x,y,ylab=“Response variable”,xlab=“Explanatory variable”) plot(x,y,pch=3,ylab=“Response variable”,xlab=“Explanatory variable”)

Open triangles are plotting character pch=2

plot(x,y,pch=2,ylab=“Response variable”,xlab=“Explanatory variable”)

abline(lm(y~x))

lines(c(0,10),c(12,0),lty=2)

v<-c(2,4,6,8,10) w<-c(8,5,6,6,2)

points(v,w,pch=3)

abline(lm(w~v),lty=3) sex<-c(“male”,“female”) weather<-read.table(“c:\temp\SilwoodWeather.txt”,header=T)

[1] “upper” “lower” “rain” “month” “yr”

attach(weather) month<-factor(month)

is.factor(month)

plot(month,upper)

pie(rep(1, 30), col = rainbow(30), radius = 0.9) pie(rep(1, 10), col = rainbow(10), radius = 0.5)

x<-seq(0,10,0.1) y1 <- 2 + 3 * x - 0.25 * x ^ 2

y2 <- 3 + 3.3 * x - 0.3 * x ^ 2

par(bg=“ghostwhite”)

plot(x,y2,type=“n”,ylab=“”)

lines(x,y2,col=“red”) lines(x,y1,col=“blue”)

jantemps<-read.table(“c:\temp\jantemp.txt”,header=T) attach(jantemps) names(jantemps

max(tmax) [1] 10.8

min(tmin) [1] -11.5

plot(day,tmax,ylim=c(-12,12),type=“n”,ylab=“Temperature”)

points(day,tmin,col=“blue”,pch=16) points(day,tmax,col=“red”,pch=16)

for (i in 1:31) lines(c(i ,i ), c( tmin[i], tmax[i] ), col=“green”)

x <- rnorm(1000)

par(bg = “cornsilk”)

hist(x, col = “lavender”, main = “”)

fate <- c(0.12, 0.3, 0.26, 0.16, 0.04, 0.12)

names(fate)<-c(“Ragwort”,“Thistle”,“Willowherb”,“Rush”,“Orchid”,“Knapweed”)

pie(fate, col = c(“purple”, “violetred1”, “green3”, “cornsilk”, “cyan”, “white”))

pollution<-read.csv(“pollute.csv”,header=TRUE) attach(pollution)

names(pollution)

pairs(pollution,panel=panel.smooth)

library(tree)

regtree<-tree(Pollution ~ . , data=pollution)

plot(regtree) text(regtree)

attach(pollute) coplot(Pollution~Temp | Rain)

par(mfrow=c(1,1)) par(mfrow=c(1,2)) par(mfrow=c(2,2))

plotdata<-read.txt(“plotdata.txt”,header =TRUE)

attach(plotdata) names(plotdata)

par(mfrow=c(2,2))

plot(xvalues,yvalues,type=“l”) plot(xvalues,yvalues,log=“xy”,type=“l”) plot(xvalues,yvalues,log=“y”,type=“l”) ploT(xvalues,yvalues,log=“x”,type=“l”)

par(mfrow=c(1,2)) plot(xvalues,yvalues,type=“l”) plot(xvalues,yvalues,ylim=c(0,50),type=“l”

text(0.8,45,“(b)”)

map.data<-read.csv(“bowens.csv”,header=TRUE) attach(map.data) names(map.data)

nn<-ifelse(north<60,north+100,north)

plot(c(20,100),c(60,110),type=“n”,xlab=“”,ylab=“”)

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) }

labels<-letters[1:10]

plot(1:10,1:10,type=“n”) text(1:10,1:10,labels,cex=2) plot(1:10,1:10,type=“n”) text(1:10,10:1,labels,cex=2,srt=180)