###CLIMAS### informacion sobre climas
options(repos = list(CRAN="http://cran.rstudio.com/"))
install.packages('riem')
## Warning in download.file(url, destfile, method, mode = "wb", ...): URL
## 'http://cran.rstudio.com/bin/windows/contrib/4.2/riem_0.3.0.zip': status was
## 'Failure when receiving data from the peer'
## Error in download.file(url, destfile, method, mode = "wb", ...) :
## no fue posible abrir la URL 'http://cran.rstudio.com/bin/windows/contrib/4.2/riem_0.3.0.zip'
## Warning in download.packages(pkgs, destdir = tmpd, available = available, :
## download of package 'riem' failed
library(riem)
install.packages('tidyverse')
## package 'tidyverse' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Invitad2\AppData\Local\Temp\RtmpyIx366\downloaded_packages
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.0 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.1 ✔ tibble 3.1.8
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
install.packages('lubridate')
## Warning: package 'lubridate' is in use and will not be installed
library(lubridate)
install.packages('ggplot2')
## Warning: package 'ggplot2' is in use and will not be installed
library(ggplot2)
install.packages('plotly')
## Warning in download.file(url, destfile, method, mode = "wb", ...): URL
## 'http://cran.rstudio.com/bin/windows/contrib/4.2/plotly_4.10.1.zip': status was
## 'Failure when receiving data from the peer'
## Error in download.file(url, destfile, method, mode = "wb", ...) :
## no fue posible abrir la URL 'http://cran.rstudio.com/bin/windows/contrib/4.2/plotly_4.10.1.zip'
## Warning in download.packages(pkgs, destdir = tmpd, available = available, :
## download of package 'plotly' failed
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
# Paso 2 Buscar la red (país).
view(riem_networks())
# Paso 3 Buscar la estación (ciudad) y copiar ID
view(riem_stations('MX__ASOS'))
#Paso 4 Obtener informacion
monterrey<- riem_measures("MMMY")
# Paso 5 Agregar Temperatura en grados centigrados
monterrey$tmpc<- (monterrey$tmpf -32)/1.8
str(monterrey)
## tibble [82,414 × 33] (S3: tbl_df/tbl/data.frame)
## $ station : chr [1:82414] "MMMY" "MMMY" "MMMY" "MMMY" ...
## $ valid : POSIXct[1:82414], format: "2014-01-01 00:16:00" "2014-01-01 00:49:00" ...
## $ lon : num [1:82414] -100 -100 -100 -100 -100 ...
## $ lat : num [1:82414] 25.8 25.8 25.8 25.8 25.8 ...
## $ tmpf : num [1:82414] 48.2 48.2 48.2 46.4 46.4 46.4 46.4 46.4 46.4 46.4 ...
## $ dwpf : num [1:82414] 46.4 46.4 46.4 46.4 46.4 44.6 44.6 44.6 44.6 44.6 ...
## $ relh : num [1:82414] 93.5 93.5 93.5 100 100 ...
## $ drct : num [1:82414] 0 120 120 120 110 100 110 130 60 0 ...
## $ sknt : num [1:82414] 0 3 5 6 5 5 4 3 3 0 ...
## $ p01i : num [1:82414] 0 0 0 0 0 0 0 0 0 0 ...
## $ alti : num [1:82414] 30.3 30.3 30.3 30.3 30.3 ...
## $ mslp : num [1:82414] NA NA NA NA NA ...
## $ vsby : num [1:82414] 4 3 1 0.25 0.12 0.12 0.06 0.06 0.06 0.12 ...
## $ gust : num [1:82414] NA NA NA NA NA NA NA NA NA NA ...
## $ skyc1 : chr [1:82414] "SCT" "SCT" "SCT" "VV " ...
## $ skyc2 : chr [1:82414] "BKN" "BKN" "BKN" NA ...
## $ skyc3 : chr [1:82414] "OVC" "OVC" "OVC" NA ...
## $ skyc4 : chr [1:82414] NA NA NA NA ...
## $ skyl1 : num [1:82414] 700 300 200 200 100 100 100 100 100 100 ...
## $ skyl2 : num [1:82414] 1200 400 300 NA NA NA NA NA NA NA ...
## $ skyl3 : num [1:82414] 4000 900 500 NA NA NA NA NA NA NA ...
## $ skyl4 : num [1:82414] NA NA NA NA NA NA NA NA NA NA ...
## $ wxcodes : chr [1:82414] NA "BR" "BR" "FG" ...
## $ ice_accretion_1hr: logi [1:82414] NA NA NA NA NA NA ...
## $ ice_accretion_3hr: logi [1:82414] NA NA NA NA NA NA ...
## $ ice_accretion_6hr: logi [1:82414] NA NA NA NA NA NA ...
## $ peak_wind_gust : logi [1:82414] NA NA NA NA NA NA ...
## $ peak_wind_drct : logi [1:82414] NA NA NA NA NA NA ...
## $ peak_wind_time : logi [1:82414] NA NA NA NA NA NA ...
## $ feel : num [1:82414] 48.2 47.2 45.6 42.9 43.5 ...
## $ metar : chr [1:82414] "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:82414] NA NA NA NA NA NA ...
## $ tmpc : num [1:82414] 9 9 9 8 8 8 8 8 8 8 ...
summary(monterrey)
## station valid lon
## Length:82414 Min. :2014-01-01 00:16:00.00 Min. :-100.1
## Class :character 1st Qu.:2016-04-24 14:03:00.00 1st Qu.:-100.1
## Mode :character Median :2018-08-06 20:13:00.00 Median :-100.1
## Mean :2018-08-10 08:48:45.13 Mean :-100.1
## 3rd Qu.:2020-11-18 06:25:00.00 3rd Qu.:-100.1
## Max. :2023-03-19 23:40:00.00 Max. :-100.1
##
## lat tmpf dwpf relh
## Min. :25.78 Min. : 23.00 Min. :-5.8 Min. : 2.32
## 1st Qu.:25.78 1st Qu.: 64.40 1st Qu.:50.0 1st Qu.: 47.79
## Median :25.78 Median : 73.40 Median :60.8 Median : 68.94
## Mean :25.78 Mean : 72.15 Mean :57.6 Mean : 65.05
## 3rd Qu.:25.78 3rd Qu.: 80.60 3rd Qu.:68.0 3rd Qu.: 83.32
## Max. :25.78 Max. :111.20 Max. :86.0 Max. :100.00
## NA's :101 NA's :1698 NA's :1743
## drct sknt p01i alti mslp
## Min. : 0.0 Min. : 0.0 Min. :0 Min. : 0.04 Min. : 913.2
## 1st Qu.: 70.0 1st Qu.: 4.0 1st Qu.:0 1st Qu.:29.88 1st Qu.:1011.4
## Median :110.0 Median : 5.0 Median :0 Median :29.97 Median :1014.5
## Mean :131.8 Mean : 5.8 Mean :0 Mean :29.98 Mean :1015.3
## 3rd Qu.:160.0 3rd Qu.: 8.0 3rd Qu.:0 3rd Qu.:30.08 3rd Qu.:1018.4
## Max. :360.0 Max. :98.0 Max. :0 Max. :30.81 Max. :1103.4
## NA's :72 NA's :72 NA's :26 NA's :71414
## vsby gust skyc1 skyc2
## Min. : 0.000 Min. : 13.00 Length:82414 Length:82414
## 1st Qu.: 6.000 1st Qu.: 20.00 Class :character Class :character
## Median :10.000 Median : 24.00 Mode :character Mode :character
## Mean : 9.112 Mean : 24.64
## 3rd Qu.:12.000 3rd Qu.: 28.00
## Max. :40.000 Max. :210.00
## NA's :31 NA's :79822
## skyc3 skyc4 skyl1 skyl2
## Length:82414 Length:82414 Min. : 0 Min. : 0
## Class :character Class :character 1st Qu.: 1500 1st Qu.: 2000
## Mode :character Mode :character Median : 3000 Median : 6000
## Mean : 5369 Mean : 7972
## 3rd Qu.: 7000 3rd Qu.:10000
## Max. :37000 Max. :30000
## NA's :24872 NA's :55309
## skyl3 skyl4 wxcodes ice_accretion_1hr
## Min. : 400 Min. : 3000 Length:82414 Mode:logical
## 1st Qu.: 8000 1st Qu.:20000 Class :character NA's:82414
## Median :15500 Median :20000 Mode :character
## Mean :14743 Mean :20656
## 3rd Qu.:20000 3rd Qu.:25000
## Max. :30000 Max. :25000
## NA's :77646 NA's :82219
## ice_accretion_3hr ice_accretion_6hr peak_wind_gust peak_wind_drct
## Mode:logical Mode:logical Mode:logical Mode:logical
## NA's:82414 NA's:82414 NA's:82414 NA's:82414
##
##
##
##
##
## peak_wind_time feel metar snowdepth
## Mode:logical Min. : 9.11 Length:82414 Mode:logical
## NA's:82414 1st Qu.: 64.40 Class :character NA's:82414
## Median : 73.40 Mode :character
## Mean : 72.76
## 3rd Qu.: 82.90
## Max. :131.06
## NA's :1746
## tmpc
## Min. :-5.00
## 1st Qu.:18.00
## Median :23.00
## Mean :22.31
## 3rd Qu.:27.00
## Max. :44.00
## NA's :101
# Paso 6 Filtrar informacion - Ejemplo Enero a Marzo 2023
este_año <- subset(monterrey, valid >= as.POSIXct('2023-01-01 00:00') & valid <= as.POSIXct('2023-03-10 07:00'))
# Paso 7 Graficar temperatura en 2023
plot(este_año$valid,este_año$tmpc)
# Paso 8 Promediar información por día
este_año <- este_año %>%
mutate(date=ymd_hms(valid), date = as.Date(date)) %>%
group_by(date) %>%
summarize_if(is.numeric, ~mean(.,na.rm = TRUE))
# Paso 9 Graficar la temperatura en 2023
plot(este_año$date,este_año$tmpc, type="l", main="Temperatura promedio en monterrey", xlab="Fecha", ylab="´Centigrados")