Comparison

Harold Nelson

2023-10-17

Setup

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.1     ✔ purrr   1.0.1
## ✔ tibble  3.2.1     ✔ dplyr   1.1.1
## ✔ tidyr   1.3.0     ✔ stringr 1.5.0
## ✔ readr   2.1.2     ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(lubridate)
## 
## Attaching package: 'lubridate'
## 
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, 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
load("OAW2309.Rdata")
load("SD2310.Rdata")

Create both

The file both should have a variable “loc”. The values of loc are “Oly” or “SanD”. It contains all records from both dataframes.

Solution

SD2310$loc = "SanD"
OAW2309$loc = "Oly"
both = rbind(SD2310,OAW2309)
summary(both)
##      DATE                PRCP              TMAX             TMIN      
##  Length:60856       Min.   :0.00000   Min.   : 18.00   Min.   :-8.00  
##  Class :character   1st Qu.:0.00000   1st Qu.: 59.00   1st Qu.:40.00  
##  Mode  :character   Median :0.00000   Median : 67.00   Median :49.00  
##                     Mean   :0.08102   Mean   : 65.73   Mean   :48.66  
##                     3rd Qu.:0.02000   3rd Qu.: 74.00   3rd Qu.:58.00  
##                     Max.   :4.82000   Max.   :111.00   Max.   :78.00  
##                                                                       
##        yr             mo              dy            loc           
##  Min.   :1939   8      : 5208   Min.   : 1.00   Length:60856      
##  1st Qu.:1961   7      : 5206   1st Qu.: 8.00   Class :character  
##  Median :1982   5      : 5160   Median :16.00   Mode  :character  
##  Mean   :1982   10     : 5159   Mean   :15.73                     
##  3rd Qu.:2002   1      : 5145   3rd Qu.:23.00                     
##  Max.   :2023   3      : 5144   Max.   :31.00                     
##                 (Other):29834

Compare Density Plots of TMAX

Solution 1

TMAX_density = both %>% 
  ggplot(aes(x = TMAX, color = loc)) +
  geom_density()
ggplotly(TMAX_density)
## Warning: The following aesthetics were dropped during statistical transformation:
## x_plotlyDomain
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?

Solution

TMAX_density = both %>% 
  ggplot(aes(x = TMAX, color = loc)) +
  geom_density() +
  facet_wrap(~loc,ncol = 1)
ggplotly(TMAX_density)
## Warning: The following aesthetics were dropped during statistical transformation:
## x_plotlyDomain
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?
## The following aesthetics were dropped during statistical transformation:
## x_plotlyDomain
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?