Skip to content

Commit 847c298

Browse files
committed
Fin del tema 4
1 parent 90f94c8 commit 847c298

3 files changed

Lines changed: 399 additions & 1 deletion

File tree

scripts/tema4/01-graficos.Rmd

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
title: "Graficos"
3+
author: "Curso de Estadística Descriptiva"
4+
date: "22/12/2018"
5+
output: html_document
6+
---
7+
8+
```{r setup, include=FALSE}
9+
knitr::opts_chunk$set(echo = TRUE)
10+
```
11+
12+
## Gráficos con la función `plot`
13+
14+
```{r primer_plot, fig.cap="Gráfico básico explicando el uso del plot", fig.align='center'}
15+
x = c(2,6,4,9,-1)
16+
y = c(1,8,4,-2,4)
17+
plot(x,y)
18+
```
19+
20+
Si no incorporamos vector `y`, `R` nos va a tomar el parámetro `x` como si fuese el vector de datos `y` : `plot(1:n, x)
21+
22+
```{r}
23+
plot(2^(1:6))
24+
```
25+
26+
Si queremos representar una función $f(x)$:
27+
28+
```{r}
29+
f <- function(x){ sqrt(x) }
30+
plot(f)
31+
```
32+
33+
## Parámetros
34+
35+
```{r, echo=FALSE, fig.align='center'}
36+
n = 1:20
37+
fib = (1/sqrt(5))*((1+sqrt(5))/2)^n - (1/sqrt(5))*((1-sqrt(5))/2)^n
38+
fib
39+
par(mfrow = c(1,2))
40+
plot(fib, xlab = "n", ylab = expression(F[n]),
41+
main = "Sucesión de Fibonacci", pch = 21, cex = 2,
42+
col = "powderblue", bg = "orchid", log = "xy")
43+
44+
plot(fib, xlab = "n", ylab = expression(F[n]),
45+
main = "Sucesión de Fibonacci", pch = 21, cex = 2,
46+
col = "powderblue", bg = "orchid", log = "y")
47+
par(mfrow = c(1,1))
48+
```
49+
50+
51+
```{r}
52+
plot(n, fib, pch = 21, col = "red", bg = "yellow", cex = 1.2,
53+
main = "Fibonacci",
54+
type = "o", lty = "dashed", lwd = 2,
55+
xlim = c(1,10), ylim = c(1, 100),
56+
xaxp = c(1,10,3), yaxp = c(0,100, 10))
57+
```
58+
59+
## Cómo añadir elementos a un gráfico
60+
```{r}
61+
f <- function(x){
62+
x^2 -2*x + sqrt(abs(x))
63+
}
64+
plot(f, xlim = c(-3,3))
65+
points(0,0, pch = 19)
66+
points(-3:3, (-3:3)^2, col = "blue")
67+
abline(2,3, lty = "dashed", col = "red")
68+
abline(v = 2, lty = "dotted", col = "green")
69+
abline(h = 5, lty = "dotdash", col = "gray")
70+
```
71+
72+
```{r}
73+
f <- function(x){x^2}
74+
plot(f, xlim = c(-3,3), col = "red", lwd = 2, ylab = expression(y^2), xlab = "x")
75+
abline(h=0:9, v = -3:3, lty="dotted", col = "grey")
76+
```
77+
78+
```{r}
79+
plot(tan, xlim = c(-pi, pi), ylim = c(-5,5))
80+
abline(v = c(-pi/2, pi/2), col = "red")
81+
```
82+
83+
```{r}
84+
plot(0,0)
85+
text(0,0, labels = "debajo", pos = 1)
86+
text(0,0, labels = "izquierda", pos = 2)
87+
text(0,0, labels = "arriba", pos = 3)
88+
text(0,0, labels = "derecha", pos = 4)
89+
points(0,1)
90+
text(0,1, labels = "centro")
91+
```
92+
93+
94+
```{r}
95+
f <- function(x){x^2}
96+
plot(f, xlim = c(-3,3), ylim = c(-10,10))
97+
points(-3:3, f(-3:3), pch = 19)
98+
lines(-3:3, f(-3:3), lwd = 2, lty = "dotted", col = "red")
99+
curve(x^3, lty = "dashed", col = "blue", add = TRUE)
100+
curve(x^4, lty = "dashed", col = "orangered", add=TRUE)
101+
legend("bottomright", legend = c(expression(x^2), expression(x^3), expression(x^4)), lwd = 2, col = c("red", "blue", "orangered"), lty = c("dotted", "dashed", "dashed"))
102+
```
103+

scripts/tema4/01-graficos.html

Lines changed: 291 additions & 0 deletions
Large diffs are not rendered by default.

teoria/Tema4.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
font-style: italic;
6464
}
6565

66+
summary {
67+
display: list-item;
68+
}
69+
6670
slides > slide {
6771
-webkit-transition: all 0.4s ease-in-out;
6872
-moz-transition: all 0.4s ease-in-out;
@@ -96,7 +100,7 @@
96100
}
97101
</style>
98102

99-
<link href="data:text/css;charset=utf-8,%2Ealigncenter%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0A%2Eexercise%20%7B%0Abackground%2Dcolor%3A%20green%3B%0Acolor%3A%20white%3B%0Aopacity%3A%200%2E5%3B%0Afont%2Dsize%3A%200%2E8em%3B%0A%7D%0A%2Eexample%7B%0Acolor%3A%20white%3B%0Abackground%2Dcolor%3A%20blue%3B%0Aopacity%3A%200%2E5%3B%0Afont%2Dsize%3A%200%2E8em%3B%0A%7D%0A%2Eimportant%7B%0Acolor%3A%20red%3B%0Adisplay%3Ainline%3B%0A%7D%0A%2Edefinition%7B%0Acolor%3A%20blue%3B%0Adisplay%3Ainline%3B%0A%7D%0A%2Ebox%7B%0Aborder%2Dradius%3A%2010px%2010px%2010px%2010px%3B%0A%2Dmoz%2Dborder%2Dradius%3A%2010px%2010px%2010px%2010px%3B%0A%2Dwebkit%2Dborder%2Dradius%3A%2010px%2010px%2010px%2010px%3B%0Aborder%3A%202px%20solid%20blue%3B%0Aopacity%3A%200%2E5%3B%0A%7D%0A%2Edem%20%7B%0Abackground%2Dcolor%3A%20gray%3B%0Acolor%3Awhite%3B%0Aopacity%3A%200%2E5%3B%0Afont%2Dsize%3A%200%2E75em%3B%0A%7D%0A%2Er%2Dcode%7B%0Aborder%2Dradius%3A%2010px%2010px%2010px%2010px%3B%0A%2Dmoz%2Dborder%2Dradius%3A%2010px%2010px%2010px%2010px%3B%0A%2Dwebkit%2Dborder%2Dradius%3A%2010px%2010px%2010px%2010px%3B%0Aborder%3A%202px%20solid%20gray%3B%0Abackground%2Dcolor%3A%20%23F2F2F2%3B%0Afont%2Dsize%3A%200%2E7em%0A%7D%0A" rel="stylesheet" type="text/css" />
103+
<link href="data:text/css;charset=utf-8,%2Ealigncenter%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0A%2Eexercise%20%7B%0Abackground%2Dcolor%3A%20green%3B%0Acolor%3A%20white%3B%0Aopacity%3A%200%2E5%3B%0Afont%2Dsize%3A%200%2E8em%3B%0A%7D%0A%2Eprop%7B%0Acolor%3A%20lightgreen%3B%0Adisplay%3Ainline%3B%0A%7D%0A%2Eexample%7B%0Acolor%3A%20white%3B%0Abackground%2Dcolor%3A%20blue%3B%0Aopacity%3A%200%2E5%3B%0Afont%2Dsize%3A%200%2E8em%3B%0A%7D%0A%2Eimportant%7B%0Acolor%3A%20red%3B%0Adisplay%3Ainline%3B%0A%7D%0A%2Edefinition%7B%0Acolor%3A%20blue%3B%0Adisplay%3Ainline%3B%0A%7D%0A%2Ebox%7B%0Aborder%2Dradius%3A%2010px%2010px%2010px%2010px%3B%0A%2Dmoz%2Dborder%2Dradius%3A%2010px%2010px%2010px%2010px%3B%0A%2Dwebkit%2Dborder%2Dradius%3A%2010px%2010px%2010px%2010px%3B%0Aborder%3A%202px%20solid%20blue%3B%0Aopacity%3A%200%2E5%3B%0A%7D%0A%2Edem%20%7B%0Abackground%2Dcolor%3A%20gray%3B%0Acolor%3Awhite%3B%0Aopacity%3A%200%2E5%3B%0Afont%2Dsize%3A%200%2E75em%3B%0A%7D%0A%2Er%2Dcode%7B%0Aborder%2Dradius%3A%2010px%2010px%2010px%2010px%3B%0A%2Dmoz%2Dborder%2Dradius%3A%2010px%2010px%2010px%2010px%3B%0A%2Dwebkit%2Dborder%2Dradius%3A%2010px%2010px%2010px%2010px%3B%0Aborder%3A%202px%20solid%20gray%3B%0Abackground%2Dcolor%3A%20%23F2F2F2%3B%0Afont%2Dsize%3A%200%2E7em%0A%7D%0A" rel="stylesheet" type="text/css" />
100104

101105
</head>
102106

0 commit comments

Comments
 (0)