La función hace una gráfica que nos permite ver el valor que toma una serie de números aleatorios a través del tiempo. Sólo recibe como parámetro al database sobre el cual trabajaremos.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(readxl)
G_serie <- function(serie){
n <- sample(1:1001,1,replace=FALSE); serie_n<-t(serie[n,-c(1:7)])
serie_n <- na.omit(serie_n);
serie_n <- data.frame(Tiempo=c(1:length(serie_n)), Serie=serie_n)
p <- plot_ly(data = serie_n, x= ~Tiempo, y= ~Serie,
type = 'scatter',
mode = 'lines+markers',
color = '#6A3CBD',
marker = list(size = 7,
color = '#3995BF',
line = list(color = '#6ECEFA',
width = 2))) %>%
layout(title = paste("Serie del renglón: ", n),
yaxis = list(zeroline = FALSE),
xaxis = list(zeroline = FALSE))
return(p)
}
serie <- read_excel("MC1001.xls")
## New names:
## * `` -> ...158
## * `` -> ...159
## * `` -> ...160
## * `` -> ...161
## * `` -> ...162
## * ... and 3 more problems
Dado que la función nos da ejemplos diferentes por la aleatoriedad fijaremos tres diferentes semillas y así quedará fijo cada ejemplo.
set.seed(154)
G_serie(serie)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
set.seed(56)
G_serie(serie)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
set.seed(6)
G_serie(serie)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels