################################################################################ ### TALLER FUNDAMENTOS DE R ### ### EJERCICIO 9.4: CONTROL DE FLUJO ### ### ### ### Center for Conservation and Sustainable Development ### ### Missouri Botanical Garden ### ### Website: rbasicsworkshop.weebly.com ### ################################################################################ ## OBJETIVO: ## Practicar el uso de de bucles ("loops") ## TAREA 1 ## ## Use un bucle para crear una figura similar a aquella en el archivo ## "ListOfLinesAndSymbols.pdf", disponible el la página del taller. ## La figura debe mostrar cómo los diferentes valores del argumento "lty" y ## "pch" de la función *plot.default* resulta en diferentes lineas y símbolos ## en una gráfica. Asegúrese de guardar la figura resultante en un archivo. ################################################################################ ### RESPUESTAS ################################################################# ################################################################################ ## TAREA 1 ## ## Esta tarea puede hacerse de múltiples fomras, esta es una: pdf(file="ListOfLinesAndSymbols.pdf", height=7, width=7*1.75) # Creates the pdf file par(mfrow=c(1,2)) # Splits the graphic into two panels plot(c(0.5, 7.5), c(0.5, 7.5), type="n", axes=FALSE, main="lty", ylab="", xlab="", cex.main=2) # Creates an empty graphic for(i in 1:7) # Loops through 7 options for lines { abline(h=i, lty=i, lwd=2) # Creates a line of lty type equal to "i" text(1, i, labels=i, pos=3, offset = 0.65) } plot(c(0.5, 5.5), c(0.5, 5.5), type="n", axes=FALSE, main="pch", ylab="", xlab="", cex.main=2) # Creates an empty graphic count <- 0 # Creates a variable that will increase in value counting the number # of cases that have been developed with each iteration of the loop for(i in 1:5) # Loops through 5 positions along the y axis { for(j in 1:5) # for each position in y, loops through 5 positions in x { count <- count+1 # Increases the value of the counting variable points(j, i, pch=count, cex=2, col="black", bg="grey70") # Creates a point # of pch type # equal to "count" text(j, i, labels=count, pos=2, offset = 0.65) } } dev.off()