library(readr)
salary_new <- read_csv("C:/Users/thaku/Downloads/salary_new.csv")
## New names:
## Rows: 6700 Columns: 9
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (5): Gender, Education Level, Job Title, Country, Race dbl (4): ...1, Age,
## Years of Experience, Salary
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
View(salary_new)
require(tidyverse)
## Loading required package: tidyverse
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ purrr     1.0.2
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ 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
library(class)
salary<-salary_new[-1]
salary<-na.omit(salary)
salary$`Job Title` <- sub("Social Media Man", "Social Media Manager", salary$`Job Title`)
salary$`Job Title` <- sub("Social Media Managerager", "Social Media Manager", salary$`Job Title`)

# Replace "Bachelor's Degree" with "Bachelor's" in the "Education Level" column
salary$`Education Level` <- ifelse(salary$`Education Level` == "Bachelor's Degree", "Bachelor's", salary$`Education Level`)
# Replace "Master's Degree" with "Master's" in the "Education Level" column
salary$`Education Level` <- ifelse(salary$`Education Level` == "Master's Degree", "Master's", salary$`Education Level`)

View(salary)
#write.csv(salary,"C:/Users/thaku/Dropbox/PC/Desktop/Study material/SEM V/CAP483 (DV)/data sets/salary.csv")
# Calculate basic statistics for numerical variables
summary_statistics <- summary(salary[, c("Age", "Years of Experience", "Salary")])
summary_statistics
##       Age        Years of Experience     Salary      
##  Min.   :21.00   Min.   : 0.000      Min.   :   350  
##  1st Qu.:28.00   1st Qu.: 3.000      1st Qu.: 70000  
##  Median :32.00   Median : 7.000      Median :115000  
##  Mean   :33.62   Mean   : 8.094      Mean   :115328  
##  3rd Qu.:38.00   3rd Qu.:12.000      3rd Qu.:160000  
##  Max.   :62.00   Max.   :34.000      Max.   :250000
# Calculate mean, median, and standard deviation separately
mean_age <- mean(salary$Age)
median_age <- median(salary$Age)
std_dev_age <- sd(salary$Age)

mean_experience <- mean(salary$`Years of Experience`)
median_experience <- median(salary$`Years of Experience`)
std_dev_experience <- sd(salary$`Years of Experience`)

mean_salary <- mean(salary$Salary)
median_salary <- median(salary$Salary)
std_dev_salary <- sd(salary$Salary)

#print mean, median, and standard deviation separately
cat("mean_age: ",mean_age,"\n")
## mean_age:  33.62157
cat("median_age: ",median_age,"\n")
## median_age:  32
cat("std_dev_age: ",std_dev_age,"\n")
## std_dev_age:  7.615038
cat("mean_experience: ",mean_experience,"\n")
## mean_experience:  8.094459
cat("median_experience: ",median_experience,"\n")
## median_experience:  7
cat("std_dev_experience: ",std_dev_experience,"\n")
## std_dev_experience:  6.059273
cat("mean_salary: ",mean_salary,"\n")
## mean_salary:  115327.9
cat("median_salary: ",median_salary,"\n")
## median_salary:  115000
cat("std_dev_salary: ",std_dev_salary,"\n")
## std_dev_salary:  52783.75
# Create frequency tables for categorical variables
gender_freq_table <- table(salary$Gender)
education_freq_table <- table(salary$`Education Level`)
job_title_freq_table <- table(salary$`Job Title`)
country_freq_table <- table(salary$Country)
race_freq_table <- table(salary$Race)

# Create histograms for numerical variables
par(mfrow = c(1, 3))  # Create a 1x3 grid for three plots

# Histogram for Age
hist(salary$Age, main = "Histogram of Age", xlab = "Age", col = "lightblue")

# Histogram for Years of Experience
hist(salary$`Years of Experience`, main = "Histogram of Years of Experience", xlab = "Years of Experience", col = "lightgreen")

# Histogram for Salary
hist(salary$Salary, main = "Histogram of Salary", xlab = "Salary", col = "lightcoral")

# Reset the plotting parameters
par(mfrow = c(1, 1))

# Create bar charts for categorical variables
par(mfrow = c(2, 3))  # Create a 2x3 grid for six plots

# Bar chart for Gender
barplot(gender_freq_table, main = "Gender Distribution", col = "lightblue", xlab = "Gender", ylab = "Frequency")

# Bar chart for Education Level
barplot(education_freq_table, main = "Education Level Distribution", col = "lightgreen", xlab = "Education Level", ylab = "Frequency", las = 2)

# Bar chart for Job Title
barplot(job_title_freq_table, main = "Job Title Distribution", col = "lightcoral", xlab = "Job Title", ylab = "Frequency", las = 2)

# Bar chart for Country
barplot(country_freq_table, main = "Country Distribution", col = "lavender", xlab = "Country", ylab = "Frequency", las = 2)

# Bar chart for Race
barplot(race_freq_table, main = "Race Distribution", col = "lightyellow", xlab = "Race", ylab = "Frequency", las = 2)

# Reset the plotting parameters
par(mfrow = c(1, 1))

par(mfrow = c(1, 3))
# Scatter plot of Age vs. Years of Experience
plot(salary$Age, salary$`Years of Experience`, main = "Age vs. Years of Experience", xlab = "Age", ylab = "Years of Experience", col = "blue",pch=)

# Scatter plot of Age vs. Salary
plot(salary$Age, salary$Salary, main = "Age vs. Salary", xlab = "Age", ylab = "Salary", col = "green")

# Scatter plot of Years of Experience vs. Salary
plot(salary$`Years of Experience`, salary$Salary, main = "Years of Experience vs. Salary", xlab = "Years of Experience", ylab = "Salary", col = "red")

par(mfrow = c(1, 1))


# Bar plot of Average Salary by Gender
avg_salary_by_gender <- tapply(salary$Salary, salary$Gender, mean)
barplot(avg_salary_by_gender, main = "Average Salary by Gender", xlab = "Gender", ylab = "Average Salary", col = "purple")

# Bar plot of Average Salary by Education Level
avg_salary_by_education <- tapply(salary$Salary, salary$`Education Level`, mean)
barplot(avg_salary_by_education, main = "Average Salary by Education Level", xlab = "Education Level", ylab = "Average Salary", col = "orange")

# Bar plot of Average Salary by Job Title
avg_salary_by_job_title <- tapply(salary$Salary, salary$`Job Title`, mean)
barplot(avg_salary_by_job_title, main = "Average Salary by Job Title", xlab = "Job Title", ylab = "Average Salary", col = "lightblue")

# Bar plot of Average Salary by Country
avg_salary_by_country <- tapply(salary$Salary, salary$Country, mean)
barplot(avg_salary_by_country, main = "Average Salary by Country", xlab = "Country", ylab = "Average Salary", col = "green")

# Bar plot of Average Salary by Race
avg_salary_by_race <- tapply(salary$Salary, salary$Race, mean)
barplot(avg_salary_by_race, main = "Average Salary by Race", xlab = "Race", ylab = "Average Salary", col = "red")

# Calculate the average salaries by gender
average_salaries <- tapply(salary$Salary, salary$Gender, mean)


# Create a bar chart to visualize gender-based salary differences
ggplot(data = salary, aes(x = Gender, y = Salary, fill = Gender)) +
  geom_bar(stat = "summary", fun = "mean", position = "dodge") +
  labs(
    title = "Average Salaries by Gender",
    x = "Gender",
    y = "Average Salary"
  ) +
  theme_minimal()

# Create a box plot to visualize salary distributions by education level
ggplot(data = salary, aes(x = `Education Level`, y = Salary, fill = `Education Level`)) +
  geom_boxplot() +
  labs(
    title = "Salary Distributions by Education Level",
    x = "Education Level",
    y = "Salary"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Calculate the correlation coefficient between Years of Education and Salary
correlation_coefficient <- cor(salary$Salary, salary$`Years of Experience`)

# Print the correlation coefficient
cat("Correlation Coefficient:", correlation_coefficient, "\n")
## Correlation Coefficient: 0.8088722
# Create a scatter plot to visualize the relationship
ggplot(data = salary, aes(x =`Years of Experience`, y =Salary)) +
  geom_point() +
  labs(
    title = "Scatter Plot: Years of Experience vs. Salary",
    x = "Years of Experience",
    y = "Salary"
  ) +
  theme_minimal()

# Create a bar chart to visualize the distribution of job titles
ggplot(data = salary, aes(x = `Job Title`)) +
  geom_bar() +
  labs(
    title = "Distribution of Job Titles",
    x = "Job Title",
    y = "Count"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Calculate average salaries for different job titles
average_salaries_by_job_title <- tapply(salary$Salary, salary$`Job Title`, mean)

# Print the average salaries
print(average_salaries_by_job_title)
##                       Account Manager                            Accountant 
##                              75000.00                              55000.00 
##              Administrative Assistant                    Back end Developer 
##                              50000.00                             102352.56 
##                      Business Analyst          Business Development Manager 
##                              77500.00                              90000.00 
##         Business Intelligence Analyst                                   CEO 
##                              85000.00                             250000.00 
##                    Chief Data Officer              Chief Technology Officer 
##                             220000.00                             250000.00 
##             Content Marketing Manager                            Copywriter 
##                             123150.68                              40000.00 
##                     Creative Director              Customer Service Manager 
##                             120000.00                             105000.00 
##                  Customer Service Rep       Customer Service Representative 
##                              40000.00                              33333.33 
##              Customer Success Manager                  Customer Success Rep 
##                              40000.00                              40000.00 
##                          Data Analyst                      Data Entry Clerk 
##                             125090.91                              35000.00 
##                        Data Scientist                       Delivery Driver 
##                             166105.96                              28000.00 
##              Digital Content Producer             Digital Marketing Manager 
##                              50000.00                              93269.23 
##          Digital Marketing Specialist                              Director 
##                              63333.33                             200000.00 
##      Director of Business Development              Director of Data Science 
##                             170000.00                             204561.40 
##               Director of Engineering                   Director of Finance 
##                             180000.00                             175000.00 
##                        Director of HR             Director of Human Capital 
##                             122028.99                             180000.00 
##           Director of Human Resources                 Director of Marketing 
##                             187500.00                             137840.91 
##                Director of Operations        Director of Product Management 
##                             172727.27                             175000.00 
##                     Director of Sales       Director of Sales and Marketing 
##                             175000.00                             180000.00 
##                     Event Coordinator                     Financial Advisor 
##                              52500.00                              95000.00 
##                     Financial Analyst                     Financial Manager 
##                              87692.31                             143059.70 
##                   Front end Developer                   Front End Developer 
##                              84675.32                              77419.35 
##                   Full Stack Engineer                      Graphic Designer 
##                             126719.84                              49772.73 
##                     Help Desk Analyst                         HR Generalist 
##                              35000.00                              70000.00 
##                            HR Manager           Human Resources Coordinator 
##                             110000.00                              49081.63 
##              Human Resources Director               Human Resources Manager 
##                             180000.00                             108538.46 
##                            IT Manager                 IT Support Specialist 
##                             120000.00                              60000.00 
##                Junior Account Manager                     Junior Accountant 
##                              50000.00                              41666.67 
##        Junior Advertising Coordinator               Junior Business Analyst 
##                              45000.00                              50000.00 
## Junior Business Development Associate    Junior Business Operations Analyst 
##                              40714.29                              17675.00 
##                     Junior Copywriter    Junior Customer Support Specialist 
##                              45000.00                              35000.00 
##                   Junior Data Analyst                 Junior Data Scientist 
##                              51360.00                              45000.00 
##                       Junior Designer                      Junior Developer 
##                              40000.00                              40000.00 
##              Junior Financial Advisor              Junior Financial Analyst 
##                              65000.00                              52857.14 
##                 Junior HR Coordinator                  Junior HR Generalist 
##                              37017.24                              38250.00 
##              Junior Marketing Analyst          Junior Marketing Coordinator 
##                              48333.33                              46666.67 
##              Junior Marketing Manager           Junior Marketing Specialist 
##                              63294.12                              53000.00 
##             Junior Operations Analyst         Junior Operations Coordinator 
##                              51000.00                              40000.00 
##             Junior Operations Manager                Junior Product Manager 
##                              55000.00                              56250.00 
##                Junior Project Manager                      Junior Recruiter 
##                              47000.00                              45000.00 
##             Junior Research Scientist                Junior Sales Associate 
##                              50000.00                              28211.27 
##           Junior Sales Representative           Junior Social Media Manager 
##                              36951.22                              45000.00 
##        Junior Social Media Specialist             Junior Software Developer 
##                              45000.00                              35810.34 
##              Junior Software Engineer                    Junior UX Designer 
##                              50372.55                              45000.00 
##                   Junior Web Designer                  Junior Web Developer 
##                              45000.00                              45761.90 
##                Juniour HR Coordinator                 Juniour HR Generalist 
##                              32000.00                              43000.00 
##                     Marketing Analyst                 Marketing Coordinator 
##                              62916.67                              81056.96 
##                    Marketing Director                     Marketing Manager 
##                             183984.38                             117164.71 
##                  Marketing Specialist                      Network Engineer 
##                              65000.00                              60000.00 
##                        Office Manager                    Operations Analyst 
##                              65000.00                             110000.00 
##                   Operations Director                    Operations Manager 
##                             190000.00                              95938.60 
##                    Principal Engineer                   Principal Scientist 
##                             170000.00                             120000.00 
##                      Product Designer                       Product Manager 
##                              56200.00                             142476.04 
##             Product Marketing Manager                      Project Engineer 
##                              95000.00                             115000.00 
##                       Project Manager              Public Relations Manager 
##                             119090.91                              90000.00 
##                          Receptionist                             Recruiter 
##                              25000.00                              65000.00 
##                     Research Director                    Research Scientist 
##                             163333.33                             165362.32 
##                       Sales Associate                        Sales Director 
##                              35857.14                             124112.90 
##                       Sales Executive                         Sales Manager 
##                              43026.32                             102946.43 
##              Sales Operations Manager                  Sales Representative 
##                             110000.00                              44078.95 
##              Senior Account Executive                Senior Account Manager 
##                              95000.00                             110000.00 
##                     Senior Accountant               Senior Business Analyst 
##                              85000.00                             116000.00 
##   Senior Business Development Manager                     Senior Consultant 
##                             110000.00                             140000.00 
##                   Senior Data Analyst                  Senior Data Engineer 
##                             155000.00                             155000.00 
##                 Senior Data Scientist                       Senior Engineer 
##                             151147.54                             127500.00 
##              Senior Financial Advisor              Senior Financial Analyst 
##                              93333.33                             112857.14 
##              Senior Financial Manager               Senior Graphic Designer 
##                             100000.00                             110000.00 
##                  Senior HR Generalist                     Senior HR Manager 
##                              90904.76                             150000.00 
##                  Senior HR Specialist    Senior Human Resources Coordinator 
##                             140000.00                              80000.00 
##        Senior Human Resources Manager     Senior Human Resources Specialist 
##                             109583.33                             120000.00 
##                  Senior IT Consultant             Senior IT Project Manager 
##                             110000.00                             130000.00 
##          Senior IT Support Specialist                        Senior Manager 
##                             110000.00                             160000.00 
##              Senior Marketing Analyst          Senior Marketing Coordinator 
##                              89444.44                              93333.33 
##             Senior Marketing Director              Senior Marketing Manager 
##                             160000.00                             127222.22 
##           Senior Marketing Specialist             Senior Operations Analyst 
##                              98750.00                              85000.00 
##         Senior Operations Coordinator             Senior Operations Manager 
##                              97500.00                             108000.00 
##               Senior Product Designer    Senior Product Development Manager 
##                             148000.00                             100000.00 
##                Senior Product Manager      Senior Product Marketing Manager 
##                             121666.67                             126594.20 
##            Senior Project Coordinator               Senior Project Engineer 
##                              92000.00                             166224.75 
##                Senior Project Manager      Senior Quality Assurance Analyst 
##                             129285.71                             100000.00 
##             Senior Research Scientist                     Senior Researcher 
##                             137959.18                             150000.00 
##                  Senior Sales Manager           Senior Sales Representative 
##                             132500.00                              95000.00 
##                      Senior Scientist             Senior Software Architect 
##                             123333.33                             120000.00 
##             Senior Software Developer              Senior Software Engineer 
##                             118333.33                             151326.69 
##            Senior Training Specialist                    Senior UX Designer 
##                             100000.00                             155000.00 
##                  Social Media Manager               Social Media Specialist 
##                              58000.00                              45000.00 
##                    Software Developer                     Software Engineer 
##                              64680.00                             113243.24 
##             Software Engineer Manager                      Software Manager 
##                             172502.17                             110000.00 
##              Software Project Manager                   Strategy Consultant 
##                              95000.00                             130000.00 
##                  Supply Chain Analyst                  Supply Chain Manager 
##                             130000.00                             105000.00 
##                   Technical Recruiter          Technical Support Specialist 
##                              70000.00                              40000.00 
##                      Technical Writer                   Training Specialist 
##                              45000.00                              65000.00 
##                           UX Designer                         UX Researcher 
##                              80000.00                              65000.00 
##                         VP of Finance                         Web Developer 
##                             200000.00                              66436.78
# Print the most common job titles
most_common_job_titles <- names(sort(job_title_freq_table, decreasing = TRUE))[1:5]
print(most_common_job_titles)
## [1] "Software Engineer"         "Data Scientist"           
## [3] "Software Engineer Manager" "Data Analyst"             
## [5] "Senior Project Engineer"
# Create a box plot to compare salary distributions across countries
ggplot(data = salary, aes(x = Country, y = Salary, fill = Country)) +
  geom_boxplot() +
  labs(
    title = "Salary Distributions by Country",
    x = "Country",
    y = "Salary"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Calculate average salaries by country
average_salaries_by_country <- tapply(salary$Salary, salary$Country, mean)

# Print the average salaries
print(average_salaries_by_country)
## Australia    Canada     China        UK       USA 
##  114917.4  116556.7  116271.4  115945.0  112995.5
# Create a box plot to visualize the impact of country of residence on salary
ggplot(data = salary, aes(x = Country, y = Salary, fill = Country)) +
  geom_boxplot() +
  labs(
    title = "Impact of Country of Residence on Salary",
    x = "Country",
    y = "Salary"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Create a frequency table for education levels by country
education_by_country <- table(salary$Country, salary$`Education Level`)

# Print the frequency tables for education levels by country
print(education_by_country)
##            
##             Bachelor's High School Master's PhD
##   Australia        600         103      357 276
##   Canada           584          92      384 265
##   China            624          80      361 278
##   UK               576          87      374 296
##   USA              636          86      383 254
# Create a bar chart to visualize education levels by country
ggplot(data = salary, aes(x = `Education Level`, fill = `Education Level`)) +
  geom_bar() +
  labs(
    title = "Education Levels by Country",
    x = "Education Level",
    y = "Count"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  facet_wrap(~Country, ncol = 1)  # Create separate facets for each country

# Create a frequency table for job titles by country
job_titles_by_country <- table(salary$Country, salary$`Job Title`)

# Print the frequency tables for job titles by country
print(job_titles_by_country)
##            
##             Account Manager Accountant Administrative Assistant
##   Australia               1          0                        0
##   Canada                  0          0                        1
##   China                   0          0                        0
##   UK                      0          1                        1
##   USA                     0          0                        0
##            
##             Back end Developer Business Analyst Business Development Manager
##   Australia                 43                1                            0
##   Canada                    47                0                            1
##   China                     42                1                            0
##   UK                        55                0                            0
##   USA                       57                0                            0
##            
##             Business Intelligence Analyst CEO Chief Data Officer
##   Australia                             1   0                  0
##   Canada                                0   1                  0
##   China                                 0   0                  0
##   UK                                    0   0                  0
##   USA                                   0   0                  1
##            
##             Chief Technology Officer Content Marketing Manager Copywriter
##   Australia                        0                        13          0
##   Canada                           1                        19          0
##   China                            0                        13          0
##   UK                               0                        17          0
##   USA                              0                        11          1
##            
##             Creative Director Customer Service Manager Customer Service Rep
##   Australia                 0                        0                    0
##   Canada                    1                        0                    1
##   China                     0                        2                    0
##   UK                        0                        0                    0
##   USA                       0                        0                    0
##            
##             Customer Service Representative Customer Success Manager
##   Australia                               0                        0
##   Canada                                  2                        0
##   China                                   0                        0
##   UK                                      3                        0
##   USA                                     1                        1
##            
##             Customer Success Rep Data Analyst Data Entry Clerk Data Scientist
##   Australia                    0           78                0             98
##   Canada                       1           67                0            102
##   China                        0           78                0             65
##   UK                           0           66                1             98
##   USA                          0           74                0             90
##            
##             Delivery Driver Digital Content Producer Digital Marketing Manager
##   Australia               3                        0                        13
##   Canada                  1                        0                         6
##   China                   0                        0                        12
##   UK                      1                        1                        10
##   USA                     0                        0                        11
##            
##             Digital Marketing Specialist Director
##   Australia                            3        0
##   Canada                               5        0
##   China                                5        0
##   UK                                   1        0
##   USA                                  1        1
##            
##             Director of Business Development Director of Data Science
##   Australia                                1                       12
##   Canada                                   0                       13
##   China                                    0                       11
##   UK                                       0                        9
##   USA                                      0                       12
##            
##             Director of Engineering Director of Finance Director of HR
##   Australia                       0                   2             15
##   Canada                          0                   0              9
##   China                           2                   0             15
##   UK                              0                   0             13
##   USA                             0                   0             17
##            
##             Director of Human Capital Director of Human Resources
##   Australia                         0                           0
##   Canada                            0                           0
##   China                             0                           1
##   UK                                1                           0
##   USA                               0                           1
##            
##             Director of Marketing Director of Operations
##   Australia                    17                      2
##   Canada                       22                      1
##   China                        17                      2
##   UK                           19                      3
##   USA                          13                      3
##            
##             Director of Product Management Director of Sales
##   Australia                              0                 0
##   Canada                                 0                 1
##   China                                  0                 0
##   UK                                     0                 0
##   USA                                    1                 0
##            
##             Director of Sales and Marketing Event Coordinator Financial Advisor
##   Australia                               0                 1                 0
##   Canada                                  0                 0                 0
##   China                                   1                 1                 0
##   UK                                      0                 0                 1
##   USA                                     0                 0                 0
##            
##             Financial Analyst Financial Manager Front end Developer
##   Australia                 7                34                  50
##   Canada                    7                23                  48
##   China                     9                30                  39
##   UK                        9                28                  48
##   USA                       7                19                  56
##            
##             Front End Developer Full Stack Engineer Graphic Designer
##   Australia                   4                  54                5
##   Canada                      6                  58                5
##   China                       8                  73                4
##   UK                          6                  64                3
##   USA                         7                  59                5
##            
##             Help Desk Analyst HR Generalist HR Manager
##   Australia                 0             0          0
##   Canada                    0             0          0
##   China                     0             0          1
##   UK                        0             1          1
##   USA                       1             1          0
##            
##             Human Resources Coordinator Human Resources Director
##   Australia                          11                        0
##   Canada                             10                        1
##   China                               9                        0
##   UK                                  7                        0
##   USA                                12                        0
##            
##             Human Resources Manager IT Manager IT Support Specialist
##   Australia                      21          1                     0
##   Canada                         17          0                     0
##   China                          24          0                     0
##   UK                             23          0                     0
##   USA                            19          0                     1
##            
##             Junior Account Manager Junior Accountant
##   Australia                      1                 1
##   Canada                         1                 0
##   China                          0                 0
##   UK                             0                 2
##   USA                            0                 0
##            
##             Junior Advertising Coordinator Junior Business Analyst
##   Australia                              0                       2
##   Canada                                 0                       2
##   China                                  0                       0
##   UK                                     1                       2
##   USA                                    0                       2
##            
##             Junior Business Development Associate
##   Australia                                     2
##   Canada                                        1
##   China                                         2
##   UK                                            0
##   USA                                           2
##            
##             Junior Business Operations Analyst Junior Copywriter
##   Australia                                  0                 0
##   Canada                                     0                 0
##   China                                      0                 0
##   UK                                         1                 1
##   USA                                        1                 0
##            
##             Junior Customer Support Specialist Junior Data Analyst
##   Australia                                  0                   5
##   Canada                                     0                   6
##   China                                      0                   4
##   UK                                         0                   3
##   USA                                        1                   7
##            
##             Junior Data Scientist Junior Designer Junior Developer
##   Australia                     0               1                1
##   Canada                        1               0                0
##   China                         0               0                0
##   UK                            0               0                0
##   USA                           0               0                0
##            
##             Junior Financial Advisor Junior Financial Analyst
##   Australia                        0                        1
##   Canada                           0                        2
##   China                            0                        1
##   UK                               0                        2
##   USA                              1                        1
##            
##             Junior HR Coordinator Junior HR Generalist Junior Marketing Analyst
##   Australia                     9                   12                        1
##   Canada                        7                   13                        0
##   China                         5                   12                        0
##   UK                            5                   10                        0
##   USA                           3                   13                        2
##            
##             Junior Marketing Coordinator Junior Marketing Manager
##   Australia                            1                        8
##   Canada                               3                        8
##   China                                1                       13
##   UK                                   0                       13
##   USA                                  1                        9
##            
##             Junior Marketing Specialist Junior Operations Analyst
##   Australia                           2                         1
##   Canada                              2                         2
##   China                               0                         0
##   UK                                  1                         1
##   USA                                 0                         1
##            
##             Junior Operations Coordinator Junior Operations Manager
##   Australia                             1                         1
##   Canada                                0                         1
##   China                                 0                         1
##   UK                                    0                         0
##   USA                                   0                         0
##            
##             Junior Product Manager Junior Project Manager Junior Recruiter
##   Australia                      0                      1                1
##   Canada                         2                      1                0
##   China                          1                      0                0
##   UK                             0                      2                0
##   USA                            1                      1                0
##            
##             Junior Research Scientist Junior Sales Associate
##   Australia                         0                     34
##   Canada                            0                     29
##   China                             1                     21
##   UK                                0                     26
##   USA                               0                     32
##            
##             Junior Sales Representative Junior Social Media Manager
##   Australia                          12                           1
##   Canada                              3                           0
##   China                               8                           0
##   UK                                  6                           0
##   USA                                12                           0
##            
##             Junior Social Media Specialist Junior Software Developer
##   Australia                              0                        21
##   Canada                                 0                        10
##   China                                  0                         8
##   UK                                     1                         7
##   USA                                    0                        12
##            
##             Junior Software Engineer Junior UX Designer Junior Web Designer
##   Australia                       14                  0                   0
##   Canada                           4                  0                   0
##   China                           10                  0                   1
##   UK                              12                  0                   0
##   USA                             11                  1                   0
##            
##             Junior Web Developer Juniour HR Coordinator Juniour HR Generalist
##   Australia                   14                      0                     0
##   Canada                       6                      2                     0
##   China                        8                      1                     2
##   UK                           7                      0                     1
##   USA                          7                      0                     0
##            
##             Marketing Analyst Marketing Coordinator Marketing Director
##   Australia                20                    20                 13
##   Canada                   23                    35                 15
##   China                    25                    38                 14
##   UK                       40                    30                  7
##   USA                      24                    35                 15
##            
##             Marketing Manager Marketing Specialist Network Engineer
##   Australia                39                    0                0
##   Canada                   55                    1                0
##   China                    48                    0                1
##   UK                       58                    0                0
##   USA                      55                    0                0
##            
##             Office Manager Operations Analyst Operations Director
##   Australia              0                  0                   0
##   Canada                 0                  0                   1
##   China                  0                  1                   0
##   UK                     0                  0                   0
##   USA                    1                  0                   0
##            
##             Operations Manager Principal Engineer Principal Scientist
##   Australia                 20                  0                   0
##   Canada                    16                  0                   0
##   China                     28                  0                   0
##   UK                        17                  0                   1
##   USA                       33                  1                   0
##            
##             Product Designer Product Manager Product Marketing Manager
##   Australia                9              64                         0
##   Canada                  14              61                         0
##   China                   19              60                         1
##   UK                      17              57                         0
##   USA                     16              71                         0
##            
##             Project Engineer Project Manager Public Relations Manager
##   Australia                0               8                        0
##   Canada                   0               3                        0
##   China                    1               2                        0
##   UK                       0               2                        1
##   USA                      0               7                        0
##            
##             Receptionist Recruiter Research Director Research Scientist
##   Australia           13         0                13                 15
##   Canada              11         0                17                 15
##   China               11         1                15                 15
##   UK                  11         0                18                 14
##   USA                 11         1                12                 10
##            
##             Sales Associate Sales Director Sales Executive Sales Manager
##   Australia              17             11               6            10
##   Canada                 17              9              10            17
##   China                  11             16               8            15
##   UK                     10              5              10             7
##   USA                    15             21               4             7
##            
##             Sales Operations Manager Sales Representative
##   Australia                        0                    8
##   Canada                           0                    5
##   China                            0                    9
##   UK                               1                    8
##   USA                              0                    8
##            
##             Senior Account Executive Senior Account Manager Senior Accountant
##   Australia                        0                      1                 0
##   Canada                           0                      0                 1
##   China                            0                      0                 0
##   UK                               0                      0                 0
##   USA                              1                      0                 1
##            
##             Senior Business Analyst Senior Business Development Manager
##   Australia                       2                                   0
##   Canada                          1                                   1
##   China                           3                                   1
##   UK                              3                                   0
##   USA                             1                                   2
##            
##             Senior Consultant Senior Data Analyst Senior Data Engineer
##   Australia                 0                   0                    2
##   Canada                    1                   0                    2
##   China                     0                   0                    0
##   UK                        0                   3                    0
##   USA                       0                   0                    0
##            
##             Senior Data Scientist Senior Engineer Senior Financial Advisor
##   Australia                     8               0                        1
##   Canada                       14               0                        1
##   China                        17               0                        0
##   UK                           13               1                        1
##   USA                           9               1                        0
##            
##             Senior Financial Analyst Senior Financial Manager
##   Australia                        3                        2
##   Canada                           2                        1
##   China                            0                        1
##   UK                               1                        0
##   USA                              1                        1
##            
##             Senior Graphic Designer Senior HR Generalist Senior HR Manager
##   Australia                       0                    8                 1
##   Canada                          0                    5                 1
##   China                           0                    7                 0
##   UK                              0                   11                 1
##   USA                             1                   11                 0
##            
##             Senior HR Specialist Senior Human Resources Coordinator
##   Australia                    0                                  0
##   Canada                       0                                  0
##   China                        1                                  0
##   UK                           0                                  1
##   USA                          0                                  0
##            
##             Senior Human Resources Manager Senior Human Resources Specialist
##   Australia                             10                                 0
##   Canada                                 8                                 0
##   China                                 11                                 0
##   UK                                    11                                 1
##   USA                                    8                                 0
##            
##             Senior IT Consultant Senior IT Project Manager
##   Australia                    1                         0
##   Canada                       0                         0
##   China                        1                         1
##   UK                           0                         0
##   USA                          0                         0
##            
##             Senior IT Support Specialist Senior Manager
##   Australia                            0              0
##   Canada                               0              1
##   China                                0              0
##   UK                                   0              0
##   USA                                  1              1
##            
##             Senior Marketing Analyst Senior Marketing Coordinator
##   Australia                        0                            0
##   Canada                           4                            1
##   China                            2                            2
##   UK                               1                            0
##   USA                              2                            0
##            
##             Senior Marketing Director Senior Marketing Manager
##   Australia                         0                        2
##   Canada                            0                        2
##   China                             0                        2
##   UK                                1                        3
##   USA                               0                        0
##            
##             Senior Marketing Specialist Senior Operations Analyst
##   Australia                           0                         0
##   Canada                              2                         1
##   China                               0                         1
##   UK                                  1                         0
##   USA                                 1                         0
##            
##             Senior Operations Coordinator Senior Operations Manager
##   Australia                             0                         1
##   Canada                                1                         1
##   China                                 2                         1
##   UK                                    1                         1
##   USA                                   0                         1
##            
##             Senior Product Designer Senior Product Development Manager
##   Australia                       2                                  0
##   Canada                          0                                  0
##   China                           3                                  0
##   UK                              0                                  0
##   USA                             0                                  1
##            
##             Senior Product Manager Senior Product Marketing Manager
##   Australia                      1                                9
##   Canada                         2                               13
##   China                          3                               20
##   UK                             0                               16
##   USA                            0                               11
##            
##             Senior Project Coordinator Senior Project Engineer
##   Australia                          0                      72
##   Canada                             2                      70
##   China                              0                      61
##   UK                                 2                      56
##   USA                                1                      59
##            
##             Senior Project Manager Senior Quality Assurance Analyst
##   Australia                      1                                0
##   Canada                         4                                0
##   China                          0                                0
##   UK                             2                                1
##   USA                            0                                0
##            
##             Senior Research Scientist Senior Researcher Senior Sales Manager
##   Australia                        10                 0                    0
##   Canada                            5                 1                    0
##   China                            13                 0                    1
##   UK                               12                 0                    0
##   USA                               9                 0                    1
##            
##             Senior Sales Representative Senior Scientist
##   Australia                           0                2
##   Canada                              0                0
##   China                               1                0
##   UK                                  0                1
##   USA                                 1                0
##            
##             Senior Software Architect Senior Software Developer
##   Australia                         1                         1
##   Canada                            0                         2
##   China                             0                         0
##   UK                                0                         0
##   USA                               0                         0
##            
##             Senior Software Engineer Senior Training Specialist
##   Australia                       44                          0
##   Canada                          53                          1
##   China                           53                          0
##   UK                              45                          0
##   USA                             49                          0
##            
##             Senior UX Designer Social Media Manager Social Media Specialist
##   Australia                  1                    1                       0
##   Canada                     0                    5                       1
##   China                      0                    2                       0
##   UK                         1                    1                       0
##   USA                        1                    6                       0
##            
##             Software Developer Software Engineer Software Engineer Manager
##   Australia                 28               102                        74
##   Canada                    16               108                        64
##   China                     29                99                        84
##   UK                        24               102                        81
##   USA                       28               107                        73
##            
##             Software Manager Software Project Manager Strategy Consultant
##   Australia                1                        0                   0
##   Canada                   0                        0                   0
##   China                    0                        0                   0
##   UK                       0                        1                   1
##   USA                      0                        0                   0
##            
##             Supply Chain Analyst Supply Chain Manager Technical Recruiter
##   Australia                    0                    0                   0
##   Canada                       0                    0                   0
##   China                        0                    0                   0
##   UK                           1                    1                   1
##   USA                          0                    0                   0
##            
##             Technical Support Specialist Technical Writer Training Specialist
##   Australia                            0                1                   0
##   Canada                               0                0                   0
##   China                                1                0                   0
##   UK                                   0                0                   0
##   USA                                  0                0                   1
##            
##             UX Designer UX Researcher VP of Finance Web Developer
##   Australia           0             0             1            17
##   Canada              0             1             0            18
##   China               0             0             0            16
##   UK                  1             0             0            19
##   USA                 0             0             0            17
# Create a frequency table for race or ethnicity
race_distribution <- table(salary$Race)

# Print the frequency table
print(race_distribution)
## 
## African American            Asian       Australian            Black 
##              354             1602              452              437 
##          Chinese         Hispanic           Korean            Mixed 
##              444              322              457              334 
##            Welsh            White 
##              333             1961
# Create a bar chart to visualize the distribution of race or ethnicity
ggplot(data = salary, aes(x = Race, fill = Race)) +
  geom_bar() +
  labs(
    title = "Distribution of Race or Ethnicity",
    x = "Race or Ethnicity",
    y = "Count"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Calculate mean salary by race or ethnicity
mean_salary_by_race <- tapply(salary$Salary, salary$Race, mean)
# Create a data frame for mean salary by race
mean_salary_by_race_df <- data.frame(Race = names(mean_salary_by_race), MeanSalary = mean_salary_by_race)

# Create a bar chart to visualize the mean salaries by race or ethnicity
ggplot(data = mean_salary_by_race_df, aes(x = Race, y = MeanSalary, fill = Race)) +
  geom_bar(stat = "identity") +
  labs(
    title = "Mean Salary by Race or Ethnicity",
    x = "Race or Ethnicity",
    y = "Mean Salary"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Create a frequency table for education level by race
education_by_race <- table(salary$Race, salary$`Education Level`)

# Convert the frequency table to a data frame
education_by_race_df <- as.data.frame.table(education_by_race)

# Rename columns for clarity
colnames(education_by_race_df) <- c("Race", "EducationLevel", "Count")

# Create a stacked bar chart to visualize education levels by race or ethnicity
ggplot(data = education_by_race_df, aes(x = Race, y = Count, fill = EducationLevel)) +
  geom_bar(stat = "identity") +
  labs(
    title = "Education Levels by Race or Ethnicity",
    x = "Race or Ethnicity",
    y = "Count"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_fill_manual(values = c("lightblue", "lightgreen", "lightyellow","lightpink","grey"))

# Create a frequency table for job titles by race
job_titles_by_race <- table(salary$Race, salary$`Job Title`)

# Convert the frequency table to a data frame
job_titles_by_race_df <- as.data.frame.table(job_titles_by_race)

# Rename columns for clarity
colnames(job_titles_by_race_df) <- c("Race", "JobTitle", "Count")

# Create a stacked bar chart to visualize job titles by race or ethnicity
ggplot(data = job_titles_by_race_df, aes(x = Race, y = Count, fill = JobTitle)) +
  geom_bar(stat = "identity") +
  labs(
    title = "Job Titles by Race or Ethnicity",
    x = "Race or Ethnicity",
    y = "Count"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Calculate the correlation coefficient between years of experience and salary
correlation_coefficient <- cor(salary$`Years of Experience`, salary$Salary)

# Print the correlation coefficient
cat("Correlation Coefficient between Years of Experience and Salary:", correlation_coefficient, "\n")
## Correlation Coefficient between Years of Experience and Salary: 0.8088722
# Create a scatter plot of years of experience vs. salary, color-coded by job title
ggplot(salary, aes(x = `Years of Experience`, y = Salary, color = `Job Title`)) +
  geom_point() +
  labs(
    title = "Relationship Between Years of Experience and Salary",
    x = "Years of Experience",
    y = "Salary"
  ) +
  theme_minimal() +
  theme(legend.position = "top")

# Calculate correlation coefficients between years of experience and salary by job title
correlation_by_job_title <- salary %>%
  group_by(`Job Title`) %>%
  summarize(
    correlation = ifelse(
      sd(`Years of Experience`) == 0 | sd(Salary) == 0,
      NA,  # Skip job titles with zero standard deviation
      cor(`Years of Experience`, Salary)
    )
  )

# Print the correlation coefficients by job title
print(n=191,correlation_by_job_title)
## # A tibble: 188 × 2
##     `Job Title`                           correlation
##     <chr>                                       <dbl>
##   1 Account Manager                            NA    
##   2 Accountant                                 NA    
##   3 Administrative Assistant                    1    
##   4 Back end Developer                          0.834
##   5 Business Analyst                           -1    
##   6 Business Development Manager               NA    
##   7 Business Intelligence Analyst              NA    
##   8 CEO                                        NA    
##   9 Chief Data Officer                         NA    
##  10 Chief Technology Officer                   NA    
##  11 Content Marketing Manager                   0.981
##  12 Copywriter                                 NA    
##  13 Creative Director                          NA    
##  14 Customer Service Manager                    1    
##  15 Customer Service Rep                       NA    
##  16 Customer Service Representative             0.987
##  17 Customer Success Manager                   NA    
##  18 Customer Success Rep                       NA    
##  19 Data Analyst                                0.647
##  20 Data Entry Clerk                           NA    
##  21 Data Scientist                              0.488
##  22 Delivery Driver                            NA    
##  23 Digital Content Producer                   NA    
##  24 Digital Marketing Manager                   0.960
##  25 Digital Marketing Specialist                1    
##  26 Director                                   NA    
##  27 Director of Business Development           NA    
##  28 Director of Data Science                    0.987
##  29 Director of Engineering                    NA    
##  30 Director of Finance                        NA    
##  31 Director of HR                              0.959
##  32 Director of Human Capital                  NA    
##  33 Director of Human Resources                -1    
##  34 Director of Marketing                       0.827
##  35 Director of Operations                      0.351
##  36 Director of Product Management             NA    
##  37 Director of Sales                          NA    
##  38 Director of Sales and Marketing            NA    
##  39 Event Coordinator                           1    
##  40 Financial Advisor                          NA    
##  41 Financial Analyst                           0.971
##  42 Financial Manager                           0.960
##  43 Front End Developer                         0.979
##  44 Front end Developer                         0.924
##  45 Full Stack Engineer                         0.850
##  46 Graphic Designer                            0.844
##  47 HR Generalist                               1    
##  48 HR Manager                                  1    
##  49 Help Desk Analyst                          NA    
##  50 Human Resources Coordinator                 0.934
##  51 Human Resources Director                   NA    
##  52 Human Resources Manager                     0.998
##  53 IT Manager                                 NA    
##  54 IT Support Specialist                      NA    
##  55 Junior Account Manager                      1    
##  56 Junior Accountant                           1    
##  57 Junior Advertising Coordinator             NA    
##  58 Junior Business Analyst                     0.990
##  59 Junior Business Development Associate       1    
##  60 Junior Business Operations Analyst         NA    
##  61 Junior Copywriter                          NA    
##  62 Junior Customer Support Specialist         NA    
##  63 Junior Data Analyst                         1    
##  64 Junior Data Scientist                      NA    
##  65 Junior Designer                            NA    
##  66 Junior Developer                           NA    
##  67 Junior Financial Advisor                   NA    
##  68 Junior Financial Analyst                    0.751
##  69 Junior HR Coordinator                       0.349
##  70 Junior HR Generalist                        0.925
##  71 Junior Marketing Analyst                    0.991
##  72 Junior Marketing Coordinator                0.970
##  73 Junior Marketing Manager                    0.930
##  74 Junior Marketing Specialist                 0.977
##  75 Junior Operations Analyst                   0.803
##  76 Junior Operations Coordinator              NA    
##  77 Junior Operations Manager                   0.999
##  78 Junior Product Manager                      0.977
##  79 Junior Project Manager                      0.975
##  80 Junior Recruiter                           NA    
##  81 Junior Research Scientist                  NA    
##  82 Junior Sales Associate                      0.766
##  83 Junior Sales Representative                 0.966
##  84 Junior Social Media Manager                NA    
##  85 Junior Social Media Specialist             NA    
##  86 Junior Software Developer                   0.809
##  87 Junior Software Engineer                   -0.395
##  88 Junior UX Designer                         NA    
##  89 Junior Web Designer                        NA    
##  90 Junior Web Developer                        0.893
##  91 Juniour HR Coordinator                     NA    
##  92 Juniour HR Generalist                      NA    
##  93 Marketing Analyst                           0.948
##  94 Marketing Coordinator                       0.888
##  95 Marketing Director                          0.842
##  96 Marketing Manager                           0.919
##  97 Marketing Specialist                       NA    
##  98 Network Engineer                           NA    
##  99 Office Manager                             NA    
## 100 Operations Analyst                         NA    
## 101 Operations Director                        NA    
## 102 Operations Manager                          0.944
## 103 Principal Engineer                         NA    
## 104 Principal Scientist                        NA    
## 105 Product Designer                            0.929
## 106 Product Manager                             0.858
## 107 Product Marketing Manager                  NA    
## 108 Project Engineer                           NA    
## 109 Project Manager                             0.589
## 110 Public Relations Manager                   NA    
## 111 Receptionist                               NA    
## 112 Recruiter                                   1    
## 113 Research Director                           0.863
## 114 Research Scientist                          0.697
## 115 Sales Associate                             0.948
## 116 Sales Director                              0.782
## 117 Sales Executive                             0.991
## 118 Sales Manager                               0.900
## 119 Sales Operations Manager                   NA    
## 120 Sales Representative                        0.966
## 121 Senior Account Executive                   NA    
## 122 Senior Account Manager                     NA    
## 123 Senior Accountant                          -1    
## 124 Senior Business Analyst                     0.988
## 125 Senior Business Development Manager         0.904
## 126 Senior Consultant                          NA    
## 127 Senior Data Analyst                        -0.866
## 128 Senior Data Engineer                       NA    
## 129 Senior Data Scientist                       0.767
## 130 Senior Engineer                             1    
## 131 Senior Financial Advisor                   NA    
## 132 Senior Financial Analyst                    0.947
## 133 Senior Financial Manager                    0.976
## 134 Senior Graphic Designer                    NA    
## 135 Senior HR Generalist                        0.960
## 136 Senior HR Manager                           0.756
## 137 Senior HR Specialist                       NA    
## 138 Senior Human Resources Coordinator         NA    
## 139 Senior Human Resources Manager              0.990
## 140 Senior Human Resources Specialist          NA    
## 141 Senior IT Consultant                       NA    
## 142 Senior IT Project Manager                  NA    
## 143 Senior IT Support Specialist               NA    
## 144 Senior Manager                              1    
## 145 Senior Marketing Analyst                    0.741
## 146 Senior Marketing Coordinator                0.327
## 147 Senior Marketing Director                  NA    
## 148 Senior Marketing Manager                    0.882
## 149 Senior Marketing Specialist                 0.949
## 150 Senior Operations Analyst                  NA    
## 151 Senior Operations Coordinator               1    
## 152 Senior Operations Manager                   0.213
## 153 Senior Product Designer                    -1    
## 154 Senior Product Development Manager         NA    
## 155 Senior Product Manager                      0.991
## 156 Senior Product Marketing Manager            0.977
## 157 Senior Project Coordinator                 -0.802
## 158 Senior Project Engineer                     0.711
## 159 Senior Project Manager                      0.717
## 160 Senior Quality Assurance Analyst           NA    
## 161 Senior Research Scientist                   0.918
## 162 Senior Researcher                          NA    
## 163 Senior Sales Manager                        1    
## 164 Senior Sales Representative                NA    
## 165 Senior Scientist                            0.984
## 166 Senior Software Architect                  NA    
## 167 Senior Software Developer                   1.00 
## 168 Senior Software Engineer                    0.758
## 169 Senior Training Specialist                 NA    
## 170 Senior UX Designer                          1    
## 171 Social Media Manager                        0.969
## 172 Social Media Specialist                    NA    
## 173 Software Developer                          0.960
## 174 Software Engineer                           0.796
## 175 Software Engineer Manager                   0.666
## 176 Software Manager                           NA    
## 177 Software Project Manager                   NA    
## 178 Strategy Consultant                        NA    
## 179 Supply Chain Analyst                       NA    
## 180 Supply Chain Manager                       NA    
## 181 Technical Recruiter                        NA    
## 182 Technical Support Specialist               NA    
## 183 Technical Writer                           NA    
## 184 Training Specialist                        NA    
## 185 UX Designer                                NA    
## 186 UX Researcher                              NA    
## 187 VP of Finance                              NA    
## 188 Web Developer                               0.984
# Ensure that education level and job title are factors
salary$`Education Level` <- as.factor(salary$`Education Level`)
salary$`Job Title` <- as.factor(salary$`Job Title`)
str(salary$`Education Level`)
##  Factor w/ 4 levels "Bachelor's","High School",..: 1 3 4 1 3 1 3 1 1 4 ...
levels(salary$`Education Level`) <- c("High School","Bachelor's","Master's","PhD")
levels(salary$`Job Title`)<-unique(salary$`Job Title`)
# Create a linear regression model
model <- lm(Salary ~ `Years of Experience` + `Education Level` + `Job Title`, data = salary)

# Create theggplot for regression model
ggplot(salary, aes(x = `Years of Experience`, y = Salary)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, col = "red") +
  labs(title = "Salary vs. Years of Experience",
       x = "Years of Experience",
       y = "Salary")
## `geom_smooth()` using formula = 'y ~ x'

# Summary of the regression model
View(salary)
model_data<-subset(salary,select = c(Salary,`Years of Experience`,`Job Title`,`Education Level`))
#View(model_data)
rnum1<- sample(rep(1:6696))
model_data<-model_data[rnum1,]
model_data_train<-head(model_data,6596)
model_data_test<-tail(model_data,100)
model_final <- lm(Salary ~ `Years of Experience` + `Education Level` + `Job Title`, data = model_data_train)
model_data_test<-as.data.frame(model_data_test)
#View(model_data_test)
#View(model_data_train)
new_employee_salary <- predict(model_final, model_data_test)
print(new_employee_salary)
##         1         2         3         4         5         6         7         8 
##  71230.82 108170.26  85838.78 131375.15  50875.31  45494.13 112237.10 137470.60 
##         9        10        11        12        13        14        15        16 
## 124173.46 104939.41 105816.25 163335.86  72097.74 183413.71  80463.53 131273.24 
##        17        18        19        20        21        22        23        24 
##  45785.61  37834.55 145037.63 150025.53 145914.47 122641.64 155619.79 104939.41 
##        25        26        27        28        29        30        31        32 
##  95774.04  69929.99 132746.20 141908.68  33785.24 128908.16 185028.95 115472.94 
##        33        34        35        36        37        38        39        40 
## 102134.13 152340.31 172880.18 178146.95  67563.40 186555.60  77983.54 183413.71 
##        41        42        43        44        45        46        47        48 
## 108170.26 127119.65 178146.95 162286.64  25000.00 102407.43  63388.72 199374.45 
##        49        50        51        52        53        54        55        56 
## 145086.26  72290.52  62296.63 203020.69 139033.15  32128.65 112281.32 126883.32 
##        57        58        59        60        61        62        63        64 
## 128276.96 203020.69  78562.25 188680.48  75831.94 115472.94 105816.25 157818.40 
##        65        66        67        68        69        70        71        72 
##  50875.31 128240.21 193199.40 106052.58 215014.31 117694.31  86093.71 131273.24 
##        73        74        75        76        77        78        79        80 
## 115472.94 107014.55  26861.88 197753.92 161598.80 137858.69  38551.96  25000.00 
##        81        82        83        84        85        86        87        88 
##  72097.74 207467.11  57999.84 203020.69 224087.76 171265.80 110668.19  57096.48 
##        89        90        91        92        93        94        95        96 
##  62296.63  79950.11 107891.39 209907.98 128058.97 151813.11  66830.98 169316.27 
##        97        98        99       100 
## 179136.16 122641.64 207467.11  54492.62
ggplot(data = model_data_test, aes(x = model_data_test$Salary, y = new_employee_salary)) +
  geom_point() +
  geom_abline(intercept = 0, slope = 1, color = "red") +
  labs(
    title = "Actual vs. Predicted",
    x = "Actual",
    y = "Predicted"
  )

#some Multi Relation graphs

# graph to depict Salaries in Countries w.r.t Education Level
ggplot(salary, aes(x = `Education Level`, y = Salary, fill = Country)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(
    title = "Salaries in Countries w.r.t Education Level",
    x = "Country",
    y = "Salary"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  facet_wrap(~Country, ncol = 1)

# graph to depict Salaries in Countries w.r.t Age
ggplot(salary, aes(x = Age, y = Salary, fill = Country)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(
    title = "Salaries in Countries w.r.t Age",
    x = "Country",
    y = "Salary"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  facet_wrap(~Country, ncol = 1)

# graph to depict Salaries in Countries w.r.t Gender
ggplot(salary, aes(x = Gender, y = Salary, fill = Country)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(
    title = "Salaries in Countries w.r.t Education Level",
    x = "Country",
    y = "Salary"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  facet_wrap(~Country, ncol = 1)

# graph to depict Salaries in Countries w.r.t Race
ggplot(salary, aes(x = Race, y = Salary, fill = Country)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(
    title = "Salaries in Countries w.r.t Race",
    x = "Country",
    y = "Salary"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  facet_wrap(~Country, ncol = 1)

# graph to depict Salaries in Countries w.r.t Years of Experience
ggplot(salary, aes(x =`Years of Experience`, y = Salary, fill = Country)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(
    title = "Salaries in Countries w.r.t Years of Experience",
    x = "Country",
    y = "Salary"
  ) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  facet_wrap(~Country, ncol = 1)