En este post usare el paquete highcharter que para mi junto digraph y ploty son paquetes en donde podremos interactuar con ellos al final dejare algunas fuentes de informacion se me olvidaba tambien usare ggplot2 y los paquetes de quantmod para algunas diferencias incluyendo tambien a dygraphs sin mas que decir empecemos
##PAQUETES A UTILIZAR
library(ggplot2) ## grafcias profecionales
library(dygraphs) ## graficas interactivas
library(quantmod) ## graficos y seleccion de datos
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Version 0.4-0 included new data defaults. See ?getSymbols.
library(highcharter) ## el paquete a explorar
## Highcharts (www.highcharts.com) is a Highsoft software product which is
## not free for commercial and Governmental use
# si no posee aun estas librerias se recomienda
# lo siguiente:
# install.packages("ggplot2",dependencies = T)
getFX("USD/PEN",from = "2020-03-01")
## [1] "USD/PEN"
getSymbols.yahoo("FB",env = globalenv(),
from = "2019-01-01",
periodicity = 'daily')
## [1] "FB"
head(USDPEN)
## USD.PEN
## 2020-03-01 3.426400
## 2020-03-02 3.434508
## 2020-03-03 3.433630
## 2020-03-04 3.422910
## 2020-03-05 3.427116
## 2020-03-06 3.431060
head(FB)
## FB.Open FB.High FB.Low FB.Close FB.Volume FB.Adjusted
## 2019-01-02 128.99 137.51 128.56 135.68 28146200 135.68
## 2019-01-03 134.69 137.17 131.12 131.74 22717900 131.74
## 2019-01-04 134.01 138.00 133.75 137.95 29002100 137.95
## 2019-01-07 137.56 138.87 135.91 138.05 20089300 138.05
## 2019-01-08 139.89 143.14 139.54 142.53 26263800 142.53
## 2019-01-09 142.95 144.70 141.27 144.23 22205900 144.23
# para el tipo de cambio:
ggplot(USDPEN, aes(Index, USD.PEN)) +
geom_line(orientation = "x",col="red")+
theme_gray(base_size = 16)+
xlab("FECHA ")+ylab("USD VS PEN")+
labs(title = "TIPO DE CAMBIO",subtitle = "Epoca de la pandemia del covid-2019")
# para facebook
FB_A<-FB$FB.Adjusted
ggplot(FB, aes(Index, FB.Adjusted)) +
geom_line(orientation = "x",col="blue")+
theme_gray(base_size = 16)+
xlab("FECHA ")+ylab("PRECIO DE AJUSTADO")+
labs(title = "FACEBOOK",subtitle = "Epoca de la pandemia del covid-2019")
# para el tipo de cambio:
dygraph(USDPEN,main = "TIPO DE CAMBIO")%>%dyRangeSelector()%>%dyOptions(colors ="#9AFE2E" ,fillGraph = TRUE)
# para facebook
dygraph(FB_A,main = "PRECIOS AJUSTADOS")%>%dyRangeSelector()%>%dyOptions(colors ="#2EFEF7" ,fillGraph = TRUE)
# para el tipo de cambio
chartSeries(USDPEN,theme = "white")
# para facebook
candleChart(FB,subset = "2019::2020",theme = "black",TA="addEMA(n=50);addATR(n=14);addBBands();addMACD();addSMI()")
cambio= diff(log(USDPEN))
head(cambio) # tambien se puede usar perfomananalyctisys
## USD.PEN
## 2020-03-01 NA
## 2020-03-02 0.0023635367
## 2020-03-03 -0.0002556734
## 2020-03-04 -0.0031269441
## 2020-03-05 0.0012280247
## 2020-03-06 0.0011501602
highchart(type = "stock") %>%
hc_add_series(cambio,color="green",type="line")
## Warning: `as_data_frame()` is deprecated as of tibble 2.0.0.
## Please use `as_tibble()` instead.
## The signature and semantics have changed, see `?as_tibble`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
En el grafico de linea creado se puede trabajar de manera interactiva seleccionando el tiempo de vista y la fecha de inicio y final
highchart(type = "stock") %>%
hc_add_series(cambio,color="#FE9A2E",type="column")
highchart(type = "stock") %>%
hc_add_series(cambio,color="#FE9A2E",type="scatter")
hchart(FB) %>% hc_add_theme(hc_theme_superheroes())
Es un paqute muy chulo de aprender por mi cuenta lo vi hoy haci que te que te mencione unos graficos y sobre todo este paquete que es muy bueno se usa mucho para la ciencia de datos espero que aun futuro distante venirte hablar sobre este paquete y muchos mas aplicaciones de rstudio de una manera mas profesional.