## 17.3 Parameters: Local and global

• Local parameters are set in the plot command, global parameters are set for several plots
• Local
• Main=""; xlab=""; ylab="": Add titles
• xlim=c(min,max); ylim=c(min,max): Adapt axes scales
• lwd: Linewidth
• lty: Linetype (solid, dashed etc. )
• pch: Plot Symbols (circles, crosses, points, etc.)
• col: Color for points, lines etc.
• bg: Backgroundcolor for plot and certain symbols
• Global parameters (for device/window):
• par(): Set global parameters (?par), e.g. par(mfrow=c(2,2))
• mfrow: Several plots in one window
• oma: Set outer margins for plot
• mar: Set inner margins for plot
• Check out graph explaining margins

### 17.3.1 Example: Components and parameters

getwd()

# Step for step: Example 1
windows(8,8)
x <- seq(from=0,to=2*pi,length=101)
y <- sin(x) + rnorm(n=101,sd=.5)
plot(x,y, xlim=c(-1,11), ylim=c(-3,3)) #

lines(x,sin(x),col="red")

lines(c(1,5),c(-1.5,0.5)) # xcoords in first argument, y coords in second

abline(lm(y~x),lty=3)
abline(h=0)
abline(a=mean(y),b=0.1,lty=2) # a = intercept, b = slope

# labs <- paste(c("x"), 1:101, sep="")
labs <- paste(1:101) # create a character vector with labes
text(x,y, labels=labs, pos=1, cex=0.7)

# Global parameters
windows()
par(mfrow=c(2,2), oma=c(1,1,1,1), mar=c(4,4,0,0)) # try different numbers
plot(x,y)
plot(x,y)
plot(x,y)
plot(x,y)
# Try what happens if you change the global parameters
dev.off()

# SKIP

# Step for step: Example 2
x <- seq(from=0,to=2*pi,length=101)
y <- sin(x) + rnorm(n=101,sd=.5)
#
windows()
plot.default(x,y,type="n", xlab="Indep. var: x", ylab="Dep. var.: y")
# plot.default() is the default scatterplot function
lines(x,sin(x),lwd=2)
segments(x0=x,x1=x,y0=sin(x),y1=y)
points(x,y,pch=21,bg="green")
text(4,1, labels="LALALA")
dev.off()