── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ lubridate 1.9.3 ✔ tibble 3.2.1
✔ purrr 1.0.2 ✔ tidyr 1.3.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
set.seed(91755) # Seed for reproducibility
Generate synthetic dataset
x <--c(rnorm(100, mean =0.5, sd =2), # Create synthetic datarnorm(100, mean =-3, sd =4),rnorm(100, mean =2, sd =0.5))y <--c(rnorm(200, mean =1, sd =3),rnorm(100, mean =-1, sd =0.7)) +0.7* x
Create dataframe called my_data and create 3 groups and 4 subgroups
In this module, we will continue working with the airquality data set and introduce a new variable for grouping days into specific ranges. To prepare, we will install and load the dplyr and ggplot2 packages, convert the Month column to a factor class, and create a new factor variable DayRange that categorizes the Day column into ranges: <=10, 11-20, and >20.
data(airquality) # Load example data
airquality$Month <-as.factor(airquality$Month) # Convert Month to factor
airquality <- airquality %>%# Create Day rangesmutate(DayRange =factor(case_when(Day <=10~"<=10", Day >=11& Day <=20~"11-20", Day >20~">20")))
Let’s now proceed with the exercises for this module:
Create a scatter plot mapping Wind to the x-axis and Temp to the y-axis. Use facet_wrap() to create separate panels for each Month.