PS1

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

library(LSTbook)
data(AAUP)
str(AAUP)
spc_tbl_ [28 × 7] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
 $ subject : chr [1:28] "Dentistry" "Medicine" "Law" "Agriculture" ...
 $ acsal   : num [1:28] 44214 43160 40670 36879 35694 ...
 $ fem     : num [1:28] 15.7 25.5 34 12.9 4.6 13.5 16.2 7.2 29.8 14.8 ...
 $ unemp   : num [1:28] 0.1 0.2 0.5 0.8 0.5 0.3 1.1 1.2 1.4 0.3 ...
 $ nonac   : num [1:28] 99.4 96 99.3 43.4 65.5 58.1 61.9 40.7 27.4 34.2 ...
 $ nonacsal: num [1:28] 40005 50005 30518 31063 35133 ...
 $ licensed: chr [1:28] "licensed" "licensed" "licensed" "not" ...
 - attr(*, "spec")=List of 3
  ..$ cols   :List of 7
  .. ..$ subject : list()
  .. .. ..- attr(*, "class")= chr [1:2] "collector_character" "collector"
  .. ..$ acsal   : list()
  .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
  .. ..$ fem     : list()
  .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
  .. ..$ unemp   : list()
  .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
  .. ..$ nonac   : list()
  .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
  .. ..$ nonacsal: list()
  .. .. ..- attr(*, "class")= chr [1:2] "collector_double" "collector"
  .. ..$ licensed: list()
  .. .. ..- attr(*, "class")= chr [1:2] "collector_character" "collector"
  ..$ default: list()
  .. ..- attr(*, "class")= chr [1:2] "collector_guess" "collector"
  ..$ delim  : chr ","
  ..- attr(*, "class")= chr "col_spec"
 - attr(*, "problems")=<externalptr> 
summary(AAUP[, c("acsal", "nonacsal")])
     acsal          nonacsal    
 Min.   :23658   Min.   :11586  
 1st Qu.:27036   1st Qu.:19224  
 Median :30116   Median :21356  
 Mean   :30982   Mean   :25598  
 3rd Qu.:32961   3rd Qu.:32501  
 Max.   :44214   Max.   :50005  
class(AAUP$licensed)
[1] "character"
table(AAUP$licensed)

licensed      not 
       5       23 
ggplot(AAUP, aes(x=fem, y=acsal))+ geom_point()+ # Add points 
  geom_smooth(method = "lm", se= TRUE)+ # Add regression line with confidence interval
  labs("Scatter Plot of Average Academic Salary vs. Percentage of Female Faculty", x= "Percentage of Female Faculty", y= "Average Academic Salary (USD)")+ theme_minimal()
`geom_smooth()` using formula = 'y ~ x'

plot1 <- ggplot(AAUP, aes(x = fem, y = acsal)) + geom_point() + geom_smooth(method = "lm", se = TRUE) + labs( title = "Academic Salary vs. Percentage of Female Faculty", x = "Percentage of Female Faculty", y = "Average Academic Salary (USD)" ) + theme_minimal()
plot2 <- ggplot(AAUP, aes(x = nonacsal, y = acsal)) + geom_point() + geom_smooth(method = "lm", se = TRUE) + labs( title = "Academic Salary vs. Non-Academic Salary", x = "Non-Academic Salary (USD)", y = "Average Academic Salary (USD)" ) + theme_minimal() # Display both plots side by side grid.arrange(plot1, plot2, ncol = 2)
library(ggplot2) 
library(tidyr)
library(dplyr)
data("AAUP")
AAUP_long <- pivot_longer(AAUP, cols = c(fem, nonacsal), names_to = "Variable", values_to = "Value")
ggplot(AAUP_long, aes(x = Value, y = acsal)) + 
  geom_point(alpha = 0.6, color = "blue") +  # Add scatter points
  geom_smooth(method = "lm", se = TRUE, color = "red") +  # Add regression line
  facet_wrap(~Variable, scales = "free_x") +  # Separate plots for fem and nonacsal
  labs(
    title = "Scatter Plots of Academic Salary vs. Percentage of Female Faculty and Non-Academic Salary",
    x = "Variable Value",
    y = "Average Academic Salary (USD)"
  ) + 
  theme_minimal()
`geom_smooth()` using formula = 'y ~ x'