Ejercicio 8.1 Grafica de nube de puntos
#if(!is.installed('ggplot2'))
#install.packages('ggplot2')
library(ggplot2)
# Nube de puntos
qplot(Sepal.Length, Sepal.Width, data = iris, colour = Species, size = Petal.Width)

ejercicio 8.2 Graficas de lineas
qplot(Petal.Length, Sepal.Length, data=iris, color=Species) +
geom_line()

Ejercicio 8.3 Nube de puntos con regresion entre ancho y alto de
petalo por cada especie
qplot(Petal.Length, Petal.Width, data = iris, color = Species) +
geom_point() + geom_smooth()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

library(RWeka)
covertype<- read.arff('covertype.arff')
qplot(elevation, slope, data = covertype[sample(1:nrow(covertype), 500),],
geom = c("point", "smooth"), color = wilderness_area) +
theme_bw()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

Ejercicio 8.4 curva de densidad
qplot(elevation, data = covertype, geom = "density",
fill = wilderness_area)

Ejercicio 8.7 Dibujo de funciones seno y coseno
curve(sin, from = -4, to = 4, col = 'blue', lty = 'dotted', lwd = 2, ylab = 'sin(x) vs cos(x)')
curve(cos, from = -4, to = 4, col = 'cyan', lty = 'dashed', lwd = 2, add = T)
legend("topleft", c("sin(x)", "cos(x)"),
col = c('blue', 'cyan'), lty = c('dotted','dashed'), lwd = 2, ncol = 2)

Ejercicio 8.8 Dibujo de un polinomio
curve(x^3-x+1, lty = 2, from = -10, to = 10)

Ejercicio 8.9 Grafica tipo “Circos”
#if (!is.installed("circlize")) install.packages("circlize")
library(circlize)
## ========================================
## circlize version 0.4.15
## CRAN page: https://cran.r-project.org/package=circlize
## Github page: https://github.com/jokergoo/circlize
## Documentation: https://jokergoo.github.io/circlize_book/book/
##
## If you use it in published research, please cite:
## Gu, Z. circlize implements and enhances circular visualization
## in R. Bioinformatics 2014.
##
## This message can be suppressed by:
## suppressPackageStartupMessages(library(circlize))
## ========================================
mat = matrix(sample(1:100, 18, replace = TRUE), 3, 6)
rownames(mat) = letters[1:3]
colnames(mat) = LETTERS[1:6]
rn = rownames(mat)
cn = colnames(mat)
par(mar = c(1, 1, 1, 1))
circos.par(gap.degree = c(rep(2, nrow(mat) - 1), 10, rep(2, ncol(mat) - 1), 10))
chordDiagram(mat, annotationTrack = "grid", transparency = 0.5,
preAllocateTracks = list(track.height = 0.1))
for (si in get.all.sector.index()) {circos.axis(h = "top", labels.cex = 0.3, sector.index = si,
track.index = 2)
}
circos.trackPlotRegion(track.index = 1, panel.fun = function(x,y) {
xlim = get.cell.meta.data("xlim")
ylim = get.cell.meta.data("ylim")
sector.name = get.cell.meta.data("sector.index")
circos.lines(xlim, c(mean(ylim), mean(ylim)),lty = 3)
for (p in seq(0, 1, by = 0.25)) {circos.text(p * (xlim[2] - xlim[1]) + xlim[1],
mean(ylim), p, cex = 0.4, adj = c(0.5,-0.2), niceFacing = TRUE)}
circos.text(mean(xlim), 1.4, sector.name, niceFacing = TRUE)
}, bg.border = NA)
## Note: 1 point is out of plotting region in sector 'a', track '1'.
## Note: 1 point is out of plotting region in sector 'a', track '1'.
## Note: 1 point is out of plotting region in sector 'b', track '1'.
## Note: 1 point is out of plotting region in sector 'b', track '1'.
## Note: 1 point is out of plotting region in sector 'c', track '1'.
## Note: 1 point is out of plotting region in sector 'c', track '1'.
## Note: 1 point is out of plotting region in sector 'A', track '1'.
## Note: 1 point is out of plotting region in sector 'A', track '1'.
## Note: 1 point is out of plotting region in sector 'B', track '1'.
## Note: 1 point is out of plotting region in sector 'B', track '1'.
## Note: 1 point is out of plotting region in sector 'C', track '1'.
## Note: 1 point is out of plotting region in sector 'C', track '1'.
## Note: 1 point is out of plotting region in sector 'D', track '1'.
## Note: 1 point is out of plotting region in sector 'D', track '1'.
## Note: 1 point is out of plotting region in sector 'E', track '1'.
## Note: 1 point is out of plotting region in sector 'E', track '1'.
## Note: 1 point is out of plotting region in sector 'F', track '1'.
## Note: 1 point is out of plotting region in sector 'F', track '1'.

circos.clear()
Ejercicio 8.10 Grafica de “spider” o “radar”
#if (!is.installed("fmsb")) install.packages("fmsb")
library("fmsb")
set.seed(4242)
maxmin <- data.frame(emotions = c(1, 0), corel = c(1,0), scene = c(1, 0),
yeast = c(1, 0), ebay = c(1,0))
dat <- data.frame(emotions = runif(3, 0, 1), corel = runif(3,0, 1),
scene = runif(3, 0, 1), yeast = runif(3,0, 1), ebay = runif(3, 0, 1))
dat <- rbind(maxmin, dat)
radarchart(dat, axistype = 2, plty = 1:3, plwd = 2,vlabels = names(dat))

Ejercicio 8.11 Grafica tridimencional con scatterplot3d()
#if(!is.installed('scatterplot3d')) install.packages('scatterplot3d')
library('scatterplot3d')
z <- seq(-10, 10, 0.01)
x <- cos(z)
y <- sin(z)
scatterplot3d(x, y, z, highlight.3d = TRUE, col.axis = "blue",
col.grid = "lightblue", main = "Helix", pch = 20)

Ejercico 8.12 Grafica tridimencional con lattice
#if (!is.installed("lattice")) install.packages("lattice")
library("lattice")
z <- matrix(rnorm(625) + 574, nrow = 25)
z <- z + seq(50, 1, length = 25)
persp(z, phi = 30, theta = 30, zlim = c(550, 650),
xlab = "X", ylab = "Y", zlab = "Z", main = "Elevacion del terreno")

Ejercicio 8.13 Graficos de tortuga: Triangulo de Sierpinski
#if(!is.installed('TurtleGraphics'))install.packages('TurtleGraphics')
library('TurtleGraphics')
## Loading required package: grid
drawTriangle<- function(points){
turtle_setpos(points[1,1],points[1,2])
turtle_goto(points[2,1],points[2,2])
turtle_goto(points[3,1],points[3,2])
turtle_goto(points[1,1],points[1,2])
}
getMid<- function(p1,p2) c((p1[1]+p2[1])/2, c(p1[2]+p2[2])/2)
sierpinski <- function(points, degree){
drawTriangle(points)
if (degree > 0){
p1 <- matrix(c(points[1,], getMid(points[1,], points[2,]),
getMid(points[1,], points[3,])), nrow=3, byrow=TRUE)
sierpinski(p1, degree-1)
p2 <- matrix(c(points[2,], getMid(points[1,], points[2,]),
getMid(points[2,], points[3,])), nrow=3, byrow=TRUE)
sierpinski(p2, degree-1)
p3 <- matrix(c(points[3,], getMid(points[3,], points[2,]),
getMid(points[1,], points[3,])), nrow=3, byrow=TRUE)
sierpinski(p3, degree-1)
}
invisible(NULL)
}
turtle_init(520, 500, "clip")

p <- matrix(c(10, 10, 510, 10, 250, 448), nrow=3, byrow=TRUE)
turtle_col("red")
turtle_do(sierpinski(p, 6))






turtle_setpos(250, 448)





