La información obtenida es a partir del Automated Surface
Observing System (ASOS)
#file.choose()Instalar paquetes y llamar librerías
#install.packages("riem")
library(riem)
#install.packages("tidyverse")
library(tidyverse)## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.0 ✔ stringr 1.4.1
## ✔ readr 2.1.2 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
#install.packages("lubridate")
library(lubridate)##
## Attaching package: 'lubridate'
##
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
#install.packages("ggplot2")
library(ggplot2)
#install.packages("plotly")
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
Ejemplo: México y copiar CODE (MX__ASOS)
view(riem_networks())Ejemplo: Monterrey y copiar ID (MMMY)
view(riem_stations("MX__ASOS"))monterrey<-riem_measures("MMMY")str(monterrey)## tibble [77,961 × 32] (S3: tbl_df/tbl/data.frame)
## $ station : chr [1:77961] "MMMY" "MMMY" "MMMY" "MMMY" ...
## $ valid : POSIXct[1:77961], format: "2014-01-01 00:16:00" "2014-01-01 00:49:00" ...
## $ lon : num [1:77961] -100 -100 -100 -100 -100 ...
## $ lat : num [1:77961] 25.8 25.8 25.8 25.8 25.8 ...
## $ tmpf : num [1:77961] 48.2 48.2 48.2 46.4 46.4 46.4 46.4 46.4 46.4 46.4 ...
## $ dwpf : num [1:77961] 46.4 46.4 46.4 46.4 46.4 44.6 44.6 44.6 44.6 44.6 ...
## $ relh : num [1:77961] 93.5 93.5 93.5 100 100 ...
## $ drct : num [1:77961] 0 120 120 120 110 100 110 130 60 0 ...
## $ sknt : num [1:77961] 0 3 5 6 5 5 4 3 3 0 ...
## $ p01i : num [1:77961] 0 0 0 0 0 0 0 0 0 0 ...
## $ alti : num [1:77961] 30.3 30.3 30.3 30.3 30.3 ...
## $ mslp : num [1:77961] NA NA NA NA NA ...
## $ vsby : num [1:77961] 4 3 1 0.25 0.12 0.12 0.06 0.06 0.06 0.12 ...
## $ gust : num [1:77961] NA NA NA NA NA NA NA NA NA NA ...
## $ skyc1 : chr [1:77961] "SCT" "SCT" "SCT" "VV " ...
## $ skyc2 : chr [1:77961] "BKN" "BKN" "BKN" NA ...
## $ skyc3 : chr [1:77961] "OVC" "OVC" "OVC" NA ...
## $ skyc4 : chr [1:77961] NA NA NA NA ...
## $ skyl1 : num [1:77961] 700 300 200 200 100 100 100 100 100 100 ...
## $ skyl2 : num [1:77961] 1200 400 300 NA NA NA NA NA NA NA ...
## $ skyl3 : num [1:77961] 4000 900 500 NA NA NA NA NA NA NA ...
## $ skyl4 : num [1:77961] NA NA NA NA NA NA NA NA NA NA ...
## $ wxcodes : chr [1:77961] NA "BR" "BR" "FG" ...
## $ ice_accretion_1hr: logi [1:77961] NA NA NA NA NA NA ...
## $ ice_accretion_3hr: logi [1:77961] NA NA NA NA NA NA ...
## $ ice_accretion_6hr: logi [1:77961] NA NA NA NA NA NA ...
## $ peak_wind_gust : logi [1:77961] NA NA NA NA NA NA ...
## $ peak_wind_drct : logi [1:77961] NA NA NA NA NA NA ...
## $ peak_wind_time : logi [1:77961] NA NA NA NA NA NA ...
## $ feel : num [1:77961] 48.2 47.2 45.6 42.9 43.5 ...
## $ metar : chr [1:77961] "MMMY 010016Z 00000KT 4SM SCT007 BKN012 OVC040 09/08 A3028 RMK 8/5// BR" "MMMY 010049Z 12003KT 3SM BR SCT003 BKN004 OVC009 09/08 A3028 RMK 8/5// -DZ OCNL" "MMMY 010116Z 12005KT 1SM BR SCT002 BKN003 OVC005 09/08 A3028 RMK 8/6// -DZ OCNL" "MMMY 010120Z 12006KT 1/4SM FG VV002 08/08 A3029 RMK 8//// BC FG MOV SE/NW" ...
## $ snowdepth : logi [1:77961] NA NA NA NA NA NA ...
summary(monterrey)## station valid lon
## Length:77961 Min. :2014-01-01 00:16:00.00 Min. :-100.1
## Class :character 1st Qu.:2016-03-11 07:40:00.00 1st Qu.:-100.1
## Mode :character Median :2018-05-06 17:40:00.00 Median :-100.1
## Mean :2018-05-11 11:21:04.49 Mean :-100.1
## 3rd Qu.:2020-07-03 16:41:00.00 3rd Qu.:-100.1
## Max. :2022-09-19 23:40:00.00 Max. :-100.1
##
## lat tmpf dwpf relh
## Min. :25.78 Min. : 23.00 Min. :-5.80 Min. : 2.32
## 1st Qu.:25.78 1st Qu.: 64.40 1st Qu.:51.80 1st Qu.: 48.05
## Median :25.78 Median : 73.40 Median :62.60 Median : 69.14
## Mean :25.78 Mean : 72.49 Mean :57.98 Mean : 65.06
## 3rd Qu.:25.78 3rd Qu.: 80.60 3rd Qu.:68.00 3rd Qu.: 83.32
## Max. :25.78 Max. :111.20 Max. :86.00 Max. :163.20
## NA's :89 NA's :1686 NA's :1741
## drct sknt p01i alti mslp
## Min. : 0.0 Min. : 0.000 Min. :0 Min. : 0.04 Min. : 913.2
## 1st Qu.: 70.0 1st Qu.: 4.000 1st Qu.:0 1st Qu.:29.88 1st Qu.:1011.4
## Median :110.0 Median : 5.000 Median :0 Median :29.97 Median :1014.5
## Mean :130.7 Mean : 5.819 Mean :0 Mean :29.98 Mean :1015.3
## 3rd Qu.:160.0 3rd Qu.: 8.000 3rd Qu.:0 3rd Qu.:30.07 3rd Qu.:1018.4
## Max. :360.0 Max. :98.000 Max. :0 Max. :30.81 Max. :1103.4
## NA's :72 NA's :72 NA's :26 NA's :66962
## vsby gust skyc1 skyc2
## Min. : 0.000 Min. : 13.00 Length:77961 Length:77961
## 1st Qu.: 6.000 1st Qu.: 20.00 Class :character Class :character
## Median :10.000 Median : 24.00 Mode :character Mode :character
## Mean : 9.124 Mean : 24.65
## 3rd Qu.:12.000 3rd Qu.: 28.00
## Max. :40.000 Max. :210.00
## NA's :31 NA's :75505
## skyc3 skyc4 skyl1 skyl2
## Length:77961 Length:77961 Min. : 0 Min. : 0
## Class :character Class :character 1st Qu.: 1500 1st Qu.: 2000
## Mode :character Mode :character Median : 3000 Median : 6000
## Mean : 5388 Mean : 8015
## 3rd Qu.: 7000 3rd Qu.:10000
## Max. :37000 Max. :30000
## NA's :23051 NA's :51698
## skyl3 skyl4 wxcodes ice_accretion_1hr
## Min. : 400 Min. : 3000 Length:77961 Mode:logical
## 1st Qu.: 8000 1st Qu.:20000 Class :character NA's:77961
## Median :16000 Median :20000 Mode :character
## Mean :14779 Mean :20656
## 3rd Qu.:20000 3rd Qu.:25000
## Max. :30000 Max. :25000
## NA's :73228 NA's :77766
## ice_accretion_3hr ice_accretion_6hr peak_wind_gust peak_wind_drct
## Mode:logical Mode:logical Mode:logical Mode:logical
## NA's:77961 NA's:77961 NA's:77961 NA's:77961
##
##
##
##
##
## peak_wind_time feel metar snowdepth
## Mode:logical Min. : 9.11 Length:77961 Mode:logical
## NA's:77961 1st Qu.: 64.40 Class :character NA's:77961
## Median : 73.40 Mode :character
## Mean : 73.16
## 3rd Qu.: 83.29
## Max. :131.06
## NA's :1744
Ejemplo: septiembre 2022.
este_mes<-subset(monterrey, valid >= as.POSIXct("2022-09-01 00:00") & valid <=as.POSIXct("2022-09-07 23:59"))
este_mes## # A tibble: 191 × 32
## station valid lon lat tmpf dwpf relh drct sknt p01i
## <chr> <dttm> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 MMMY 2022-09-01 05:40:00 -100. 25.8 75.2 73.4 94.1 60 8 0
## 2 MMMY 2022-09-01 06:40:00 -100. 25.8 75.2 75.2 100 110 7 0
## 3 MMMY 2022-09-01 07:40:00 -100. 25.8 75.2 75.2 100 0 0 0
## 4 MMMY 2022-09-01 08:25:00 -100. 25.8 75.2 75.2 100 130 12 0
## 5 MMMY 2022-09-01 08:40:00 -100. 25.8 73.4 73.4 100 130 8 0
## 6 MMMY 2022-09-01 09:40:00 -100. 25.8 71.6 71.6 100 80 3 0
## 7 MMMY 2022-09-01 10:40:00 -100. 25.8 71.6 71.6 100 70 3 0
## 8 MMMY 2022-09-01 11:40:00 -100. 25.8 71.6 71.6 100 80 5 0
## 9 MMMY 2022-09-01 12:40:00 -100. 25.8 71.6 71.6 100 0 0 0
## 10 MMMY 2022-09-01 13:40:00 -100. 25.8 75.2 71.6 88.6 0 0 0
## # … with 181 more rows, and 22 more variables: alti <dbl>, mslp <dbl>,
## # vsby <dbl>, gust <dbl>, skyc1 <chr>, skyc2 <chr>, skyc3 <chr>, skyc4 <chr>,
## # skyl1 <dbl>, skyl2 <dbl>, skyl3 <dbl>, skyl4 <dbl>, wxcodes <chr>,
## # ice_accretion_1hr <lgl>, ice_accretion_3hr <lgl>, ice_accretion_6hr <lgl>,
## # peak_wind_gust <lgl>, peak_wind_drct <lgl>, peak_wind_time <lgl>,
## # feel <dbl>, metar <chr>, snowdepth <lgl>
Ejemplo: Humedad Relativa durante septiembre 2022.
plot(este_mes$valid,este_mes$relh)promedio<-monterrey %>%
mutate (date = ymd_hms(valid), date = as.Date(date)) %>%
group_by(date) %>%
summarize_if(is.numeric, ~mean(.,na.rm=TRUE))
tibble(promedio) ## # A tibble: 3,151 × 18
## date lon lat tmpf dwpf relh drct sknt p01i alti mslp vsby
## <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2014-01-01 -100. 25.8 50.7 47.5 90.2 90.3 2.42 0 30.2 1023. 2.29
## 2 2014-01-02 -100. 25.8 53.9 47.4 81.3 238. 8.13 0 30.2 1024. 8.48
## 3 2014-01-03 -100. 25.8 45.5 34.4 69.0 97.2 4.16 0 30.4 1030. 15
## 4 2014-01-04 -100. 25.8 44.8 36 71.7 78.9 2.22 0 30.1 1022. 15
## 5 2014-02-07 -100. 25.8 37.6 36.3 95.3 82.6 2.96 0 30.2 1026. 1.78
## 6 2014-02-08 -100. 25.8 44.8 41.5 90.0 100 2.74 0 30.2 1023. 1.81
## 7 2014-02-09 -100. 25.8 53.8 44.7 77.1 212. 5.38 0 30.1 1019. 6.46
## 8 2014-02-10 -100. 25.8 62.5 54.0 77.8 158. 7.68 0 29.9 1014. 7.27
## 9 2014-02-11 -100. 25.8 50.5 45.6 83.9 228. 7.58 0 30.0 1019. 6.81
## 10 2014-02-12 -100. 25.8 45.5 35.1 69.0 229. 8.85 0 30.2 1023. 9.56
## # … with 3,141 more rows, and 6 more variables: gust <dbl>, skyl1 <dbl>,
## # skyl2 <dbl>, skyl3 <dbl>, skyl4 <dbl>, feel <dbl>
centigrados<-promedio
centigrados$tmpc<- (centigrados$tmpf-32)/1.8
str(centigrados)## tibble [3,151 × 19] (S3: tbl_df/tbl/data.frame)
## $ date : Date[1:3151], format: "2014-01-01" "2014-01-02" ...
## $ lon : num [1:3151] -100 -100 -100 -100 -100 ...
## $ lat : num [1:3151] 25.8 25.8 25.8 25.8 25.8 ...
## $ tmpf : num [1:3151] 50.7 53.9 45.5 44.8 37.6 ...
## $ dwpf : num [1:3151] 47.5 47.4 34.4 36 36.3 ...
## $ relh : num [1:3151] 90.2 81.3 69 71.7 95.3 ...
## $ drct : num [1:3151] 90.3 238.3 97.2 78.9 82.6 ...
## $ sknt : num [1:3151] 2.42 8.13 4.16 2.22 2.96 ...
## $ p01i : num [1:3151] 0 0 0 0 0 0 0 0 0 0 ...
## $ alti : num [1:3151] 30.2 30.2 30.4 30.1 30.2 ...
## $ mslp : num [1:3151] 1023 1024 1030 1022 1026 ...
## $ vsby : num [1:3151] 2.29 8.48 15 15 1.78 ...
## $ gust : num [1:3151] NaN 27.1 NaN NaN NaN ...
## $ skyl1: num [1:3151] 1527 7150 12000 1700 348 ...
## $ skyl2: num [1:3151] 8400 10812 NaN NaN 580 ...
## $ skyl3: num [1:3151] 9080 20000 NaN NaN NaN ...
## $ skyl4: num [1:3151] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
## $ feel : num [1:3151] 49.8 53.6 44.1 43.4 34.9 ...
## $ tmpc : num [1:3151] 10.36 12.17 7.52 7.11 3.09 ...
centigrados$feelc <- (centigrados$feel-32)/1.8
str(centigrados)## tibble [3,151 × 20] (S3: tbl_df/tbl/data.frame)
## $ date : Date[1:3151], format: "2014-01-01" "2014-01-02" ...
## $ lon : num [1:3151] -100 -100 -100 -100 -100 ...
## $ lat : num [1:3151] 25.8 25.8 25.8 25.8 25.8 ...
## $ tmpf : num [1:3151] 50.7 53.9 45.5 44.8 37.6 ...
## $ dwpf : num [1:3151] 47.5 47.4 34.4 36 36.3 ...
## $ relh : num [1:3151] 90.2 81.3 69 71.7 95.3 ...
## $ drct : num [1:3151] 90.3 238.3 97.2 78.9 82.6 ...
## $ sknt : num [1:3151] 2.42 8.13 4.16 2.22 2.96 ...
## $ p01i : num [1:3151] 0 0 0 0 0 0 0 0 0 0 ...
## $ alti : num [1:3151] 30.2 30.2 30.4 30.1 30.2 ...
## $ mslp : num [1:3151] 1023 1024 1030 1022 1026 ...
## $ vsby : num [1:3151] 2.29 8.48 15 15 1.78 ...
## $ gust : num [1:3151] NaN 27.1 NaN NaN NaN ...
## $ skyl1: num [1:3151] 1527 7150 12000 1700 348 ...
## $ skyl2: num [1:3151] 8400 10812 NaN NaN 580 ...
## $ skyl3: num [1:3151] 9080 20000 NaN NaN NaN ...
## $ skyl4: num [1:3151] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
## $ feel : num [1:3151] 49.8 53.6 44.1 43.4 34.9 ...
## $ tmpc : num [1:3151] 10.36 12.17 7.52 7.11 3.09 ...
## $ feelc: num [1:3151] 9.87 12.01 6.71 6.36 1.6 ...
Ejemplo: 2022.
este_año <- centigrados[centigrados$date >= "2022-01-01" & centigrados$date <= "2022-09-07",]Ejemplo: Temperatura promedio septiembre 2022
plot(este_año$date, este_año$tmpc, type="l", main="Temperatura Promedio en Monterrey durante 2022",xlab="ºC")El código presente funge como gran ayuda para los futuros análisis de datos. Se conoce que el clima tiene un gran impacto en diferentes aspectos de la vida y de los negocios, como lo pudiera ser en las emociones y en las ventas. Por lo tanto, se considera que este código realizado, con su propia explicación, permite ser una guía para en un futuro poder obtener la variable de clima para los análisis de negocios.
Mediante estas librerías, es posible conocer las temperaturas de diferentes países, ciudades y meses. Por lo que esta herramienta aporta un gran valor y hace el análisis mucho más eficaz y eficiente, cualidad que son altamente buscadas en la analítica. Adicionalmente, resulta interesante poder comprar y conocer sobre los climas y temperaturas de otros lugar con una sola función, al descargar las librerías necesarias.