0413In class exercise 3-4
In class exercise 3:
Use R base graphics to create the national flag of Denmark :
par(pty='m')
plot.new()
plot.window(xlim=c(0, 37),
ylim=c(0, 28))
rect(xleft = c(0,12, 0), ybottom = c(0,0, 12), xright = c(37,16,37), ytop = c(28,28,16), col=c("red", "white", "white"))
rect(12, 12, 16, 16, col="white", border="white") In class exercise 4:
Run the R script to see what happens first and then explain how the effect is achieved by the script.
n <- 60
t <- seq(0, 2*pi, length=n)
x <- sin(t)
y <- cos(t)
#
par(pty = "s")
#
for (i in 1:n) {
plot.new()
plot.window(c(-1, 1), c(-1, 1))
lines(x*y, -y, col="gray")
points(x[i]*y[i], -y[i], pch=16,
col=gray((i-1)/(n+1)))
Sys.sleep(.05)
}
# using saveGIF({ for(...){...}}) to export a gif file screenshot of the plot
this animation is made by 60 plot, {Sys.sleep} Suspend execution of R expressions for time interval=0.05