DS Labs

Author

Kenny

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── 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
library(dslabs)
library(ggthemes)
data(package="dslabs")
list.files(system.file("script", package = "dslabs"))
 [1] "make-admissions.R"                   
 [2] "make-brca.R"                         
 [3] "make-brexit_polls.R"                 
 [4] "make-calificaciones.R"               
 [5] "make-death_prob.R"                   
 [6] "make-divorce_margarine.R"            
 [7] "make-gapminder-rdas.R"               
 [8] "make-greenhouse_gases.R"             
 [9] "make-historic_co2.R"                 
[10] "make-mice_weights.R"                 
[11] "make-mnist_127.R"                    
[12] "make-mnist_27.R"                     
[13] "make-movielens.R"                    
[14] "make-murders-rda.R"                  
[15] "make-na_example-rda.R"               
[16] "make-nyc_regents_scores.R"           
[17] "make-olive.R"                        
[18] "make-outlier_example.R"              
[19] "make-polls_2008.R"                   
[20] "make-polls_us_election_2016.R"       
[21] "make-pr_death_counts.R"              
[22] "make-reported_heights-rda.R"         
[23] "make-research_funding_rates.R"       
[24] "make-stars.R"                        
[25] "make-temp_carbon.R"                  
[26] "make-tissue-gene-expression.R"       
[27] "make-trump_tweets.R"                 
[28] "make-weekly_us_contagious_diseases.R"
[29] "save-gapminder-example-csv.R"        
data("admissions")
head(admissions)
  major gender admitted applicants
1     A    men       62        825
2     B    men       63        560
3     C    men       37        325
4     D    men       33        417
5     E    men       28        191
6     F    men        6        373
Graph <- admissions |> # getting the admissions dataset and filter it to include only men and women
  filter(gender %in% c("men", "women")) |> 
  ggplot(aes(x = applicants, y = admitted, color = major)) +   # Created a scatter plot with applicants on the x-axis and admitted students on the y-axis

  geom_point(alpha = 0.8, size = 3, shape = 16) + # Add points to represent data, setting transparency (alpha), size, and shape

  facet_grid(. ~ gender) + # Created two faucet plot, each representing gender 
  geom_text(aes(x = 700, y = 75, label = gender), size =8, color = "Black") + # Add gender labelson the plot
geom_smooth(method = "lm", se = FALSE, linetype = "dashed", color = "gray") + #Added a linear regression trend line without grey blur 
  labs( title = "Admission Rates by Gender Across UC Berkeley Major",
    x = "Number of Applicants",
    y = "Number of Admitted Students",
    color = "Major") + # Customize names for the title, axes, and legend

theme_bw()+   # Applied a minimal theme for a cleaner look
scale_color_brewer(palette = "Set1") # Use a color palette from the RColorBrewer to see the data better
Graph
`geom_smooth()` using formula = 'y ~ x'

The data visualization I created comes from the “admissions” dataset. This dataset highlights the gender bias present in UC Berkeley’s graduate schools. The data is separated by major and gender. I created two facet plots showing the number of applicants versus the number of admitted students for males and females. Each colored dot represents the majors that these students applied for. I also added a trend line to highlight the admission trends. The x-axis represents the number of applicants, while the y-axis shows the number of admitted students. One interesting observation I noticed is that for Major E, more women applied than men, yet more men were admitted. I found this pattern particularly intriguing.