1 + 1[1] 2
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.
When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
1 + 1[1] 2
You can add options to executable code like this
[1] 4
# "Se puede poner esto con CTRL + ALT + I" para agregar nuevos "chunks" de codigo# message: false
# warning: false
library(tidyverse)── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.4.4 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.0
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(fpp3)── Attaching packages ────────────────────────────────────────────── fpp3 0.5 ──
✔ tsibble 1.1.3 ✔ fable 0.3.3
✔ tsibbledata 0.4.1 ✔ fabletools 0.3.4
✔ feasts 0.3.1
── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
✖ lubridate::date() masks base::date()
✖ dplyr::filter() masks stats::filter()
✖ tsibble::intersect() masks base::intersect()
✖ tsibble::interval() masks lubridate::interval()
✖ dplyr::lag() masks stats::lag()
✖ tsibble::setdiff() masks base::setdiff()
✖ tsibble::union() masks base::union()
library(plotly)
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
Las “tsibbles” son data frames (“tsibbles para series de tiempo”). Tienen dos argumentos caracteristicos para series de tiempo:
gafa_stockgafa_stock |> # pipe
distinct(Symbol)pivot_wider(summarise(group_by(as_tibble(pivot_longer(gafa_stock, cols = -c(Symbol, Date), names_to = "tipo", values_to = "valor")), Symbol, tipo), media = mean(valor)), names_from = tipo, values_from = media)`summarise()` has grouped output by 'Symbol'. You can override using the
`.groups` argument.
gafa_stock |>
# pasar las columnas a filas
pivot_longer(cols = -c(Symbol, Date), names_to="tipo", values_to="valor") |>
# convertir a tibble
as_tibble() |>
# Agrupar por accion y tipo de variable
group_by(Symbol, tipo) |>
# sacar la media por grupos
summarise(media = mean(valor)) |>
# pasar los tipos de columnas
pivot_wider(names_from = Symbol, values_from = media)`summarise()` has grouped output by 'Symbol'. You can override using the
`.groups` argument.
El atajo del teclado para escribir “|>” es CTRL/CMD + SHIFT + M
gafa_stock |>
filter(Symbol == "AAPL") |>
autoplot(Close)
g1 <- gafa_stock |>
autoplot(Close) +
facet_wrap(~Symbol, scales = "free_y") + #Agrupar cada accion en una grafica sola
theme(legend.position = "none") #quitar el symbolo de cada accion
g1
ggplotly(g1)gafa_stock |>
# Quitamos el volumen puesto que no se aprecian las demas graficas
select(-Volume) |>
# Inluimos el codigo para añadir las variables que vamos a graficar
pivot_longer(cols = -c(Symbol, Date), names_to="tipo", values_to="valor") |>
autoplot(valor) + # Ponemos para tener las graficas de cada una
facet_grid(Symbol ~ tipo, scales = "free") + # Es para tener las graficas en diferentes espacios, sin esta todas las graficas estan juntas
theme(legend.position="none")