-
Notifications
You must be signed in to change notification settings - Fork 0
/
Highcharter_tempCorrientes.R
109 lines (90 loc) · 4.93 KB
/
Highcharter_tempCorrientes.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Librerías utilizadas
library(tidyverse)
library(highcharter)
library(lubridate)
# Lectura de datos
#----------------------------
#datos de cada estación meteorológica: id, long, lat, nombre, ciudad, país, etc. Cada estación corresponde a un lugar geográfico.
estaciones <- readr::read_csv("https://raw.githubusercontent.com/cienciadedatos/datos-de-miercoles/master/datos/2019/2019-10-09/estaciones.csv")
locale = readr::locale(encoding = "latin1")
View(estaciones)
#datos meteorologicos de cada estación:t_min, t_max, precipitación,etc.
meteo <- readr::read_csv("https://raw.githubusercontent.com/cienciadedatos/datos-de-miercoles/master/datos/2019/2019-10-09/meteo.csv", na = "-99.9")
View(meteo)
#----------------------------
# Procesamiento de datos
#----------------------------
# uno la tabla meteo con estacion mediane el id_estacion
estaciones_meteo <-meteo %>% inner_join(estaciones, by= 'id_estacion')%>%View()
#View(estaciones_meteo)
estaciones_meteo2 <- select(estaciones_meteo, -elevacion, -institucion)%>% filter((pais=='Argentina') & !is.na(t_max) & !is.na(t_min))%>%
mutate(fecha = as.Date(fecha), media= ((t_max+t_min)/2)) %>%
rename(Fecha = fecha)
View(estaciones_meteo2)
#selecciono datos de Corrientes Capital
datosCorrientes<- estaciones_meteo2%>% filter((year(Fecha)== 2011) & (nombre=='CORRIENTES AERO'))%>%
mutate(dia=day(Fecha))%>% select(t_max, t_min, media, Fecha,dia, nombre)
View(datosCorrientes)
#temp. mínima y máxima para definir valores del eje y
extremoInferior <- min(datosCorrientes$t_min) # -0.4
extremoSuperior <- max(datosCorrientes$t_max) # 40.7
#highcharter
x <- c("Día","T.Min.", "T.Media", "T.Máx.")
y <- sprintf("{point.%s}", c("dia","t_min", "media", "t_max"))
tltip <- tooltip_table(x, y)
#opción 1: theme monokai
#------------------------
graficoMono <-hchart(datosCorrientes, type = "columnrange",
hcaes(x = Fecha, low = t_min, high = t_max, color = media)) %>%
hc_yAxis(tickPositions = c(-5, 0, 5.0, 10.0,15.0,20.0,25.0,30.0,35.0,40.0, 45.0),
gridLineColor = "orange", #B71C1C
labels = list(format = "{value} Cº", useHTML = TRUE)) %>%
hc_tooltip(
useHTML = TRUE,
headerFormat = as.character(tags$small("{point.x: %Y %b}")),
pointFormat = tltip
) %>%
hc_add_theme(hc_theme_monokai())
graficoMono %>% hc_title(text = "Temperaturas máxima y mínima de la ciudad de Corrientes <br /> <br /> Para el período comprendido entre el 01/01/2011 y el 01/01/2012.") %>%
hc_subtitle(text = "La temperatura mínima con -0.4 Cº se registró el 27 de junio, mientras que la máxima con 40.7 Cº se registró el 22 de diciembre. <br /> <br /> Fuente: Claris LPB.")
#------------------------
# opción 2: theme ffx
#------------------------
#highcharter
x <- c("Día","T.Min.", "T.Media", "T.Máx.")
y <- sprintf("{point.%s}", c("dia","t_min", "media", "t_max"))
tltip <- tooltip_table(x, y)
grafico2 <-hchart(datosCorrientes, type = "columnrange",
hcaes(x = Fecha, low = t_min, high = t_max, color = media)) %>%
hc_yAxis(tickPositions = c(-5, 0, 5.0, 10.0,15.0,20.0,25.0,30.0,35.0,40.0, 45.0),
#gridLineColor = "orange",
labels = list(format = "{value} Cº", useHTML = TRUE)) %>%
hc_tooltip(
useHTML = TRUE,
headerFormat = as.character(tags$small("{point.x: %Y %b}")),
pointFormat = tltip
) %>%
hc_add_theme(hc_theme_ffx())
grafico2 %>% hc_title(text = "Temperaturas máxima y mínima de la ciudad de Corrientes <br /> <br /> Para el período comprendido entre el 01/01/2011 y el 01/01/2012.") %>%
hc_subtitle(text = "La temperatura mínima con -0.4 Cº se registró el 27 de junio, mientras que la máxima con 40.7 Cº se registró el 22 de diciembre. <br /> <br /> Fuente: Claris LPB.")
#--------------------------
#opción 3: theme flatdark
#--------------------------
#highcharter
x <- c("Día","T.Min.", "T.Media", "T.Máx.")
y <- sprintf("{point.%s}", c("dia","t_min", "media", "t_max"))
tltip <- tooltip_table(x, y)
grafico3 <-hchart(datosCorrientes, type = "columnrange",
hcaes(x = Fecha, low = t_min, high = t_max, color = media)) %>%
hc_yAxis(tickPositions = c(-5, 0, 5.0, 10.0,15.0,20.0,25.0,30.0,35.0,40.0, 45.0),
gridLineColor = "orange", #B71C1C
labels = list(format = "{value} Cº", useHTML = TRUE)) %>%
hc_tooltip(
useHTML = TRUE,
headerFormat = as.character(tags$small("{point.x: %Y %b}")),
pointFormat = tltip
) %>%
hc_add_theme(hc_theme_flatdark())
grafico3 %>% hc_title(text = "Temperaturas máxima y mínima de la ciudad de Corrientes <br /> <br /> Para el período comprendido entre el 01/01/2011 y el 01/01/2012.") %>%
hc_subtitle(text = "La temperatura mínima con -0.4 Cº se registró el 27 de junio, mientras que la máxima con 40.7 Cº se registró el 22 de diciembre. <br /> <br /> Fuente: Claris LPB.")
#--------------------------------------------------------------------------------