library('tidyr')
library('readr')
library('dplyr')
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library('ggplot2')
library('forcats')
library('tidyquant')
## Loading required package: lubridate
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
## Loading required package: PerformanceAnalytics
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## ######################### Warning from 'xts' package ##########################
## # #
## # The dplyr lag() function breaks how base R's lag() function is supposed to #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
## # source() into this session won't work correctly. #
## # #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
## # dplyr from breaking base R's lag() function. #
## # #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
## # #
## ###############################################################################
##
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
##
## first, last
##
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
##
## legend
## Loading required package: quantmod
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
multipleChoiceResponses <- read_csv("~/Desktop/archive/multipleChoiceResponses.csv")
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
## dat <- vroom(...)
## problems(dat)
## Rows: 16716 Columns: 228
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (212): GenderSelect, Country, EmploymentStatus, StudentStatus, LearningD...
## dbl (13): Age, LearningCategorySelftTaught, LearningCategoryOnlineCourses, ...
## num (1): CompensationAmount
## lgl (2): WorkToolsFrequencyAngoss, WorkToolsFrequencyKNIMECommercial
##
## ℹ 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.2
factor_levels <- data.frame(
variable = names(selected_columns),
num_levels = sapply(selected_columns, nlevels)
)
print(factor_levels)
## variable
## LearningDataScience LearningDataScience
## LearningPlatformSelect LearningPlatformSelect
## LearningPlatformUsefulnessArxiv LearningPlatformUsefulnessArxiv
## LearningPlatformUsefulnessBlogs LearningPlatformUsefulnessBlogs
## LearningPlatformUsefulnessCollege LearningPlatformUsefulnessCollege
## LearningPlatformUsefulnessCompany LearningPlatformUsefulnessCompany
## LearningPlatformUsefulnessConferences LearningPlatformUsefulnessConferences
## LearningPlatformUsefulnessFriends LearningPlatformUsefulnessFriends
## LearningPlatformUsefulnessKaggle LearningPlatformUsefulnessKaggle
## LearningPlatformUsefulnessNewsletters LearningPlatformUsefulnessNewsletters
## LearningPlatformUsefulnessCommunities LearningPlatformUsefulnessCommunities
## LearningPlatformUsefulnessDocumentation LearningPlatformUsefulnessDocumentation
## LearningPlatformUsefulnessCourses LearningPlatformUsefulnessCourses
## LearningPlatformUsefulnessProjects LearningPlatformUsefulnessProjects
## LearningPlatformUsefulnessPodcasts LearningPlatformUsefulnessPodcasts
## LearningPlatformUsefulnessSO LearningPlatformUsefulnessSO
## LearningPlatformUsefulnessTextbook LearningPlatformUsefulnessTextbook
## LearningPlatformUsefulnessTradeBook LearningPlatformUsefulnessTradeBook
## LearningPlatformUsefulnessTutoring LearningPlatformUsefulnessTutoring
## LearningPlatformUsefulnessYouTube LearningPlatformUsefulnessYouTube
## LearningDataScienceTime LearningDataScienceTime
## LearningCategorySelftTaught LearningCategorySelftTaught
## LearningCategoryOnlineCourses LearningCategoryOnlineCourses
## LearningCategoryWork LearningCategoryWork
## LearningCategoryUniversity LearningCategoryUniversity
## LearningCategoryKaggle LearningCategoryKaggle
## LearningCategoryOther LearningCategoryOther
## Age Age
## EmploymentStatus EmploymentStatus
## CurrentJobTitleSelect CurrentJobTitleSelect
## MLMethodNextYearSelect MLMethodNextYearSelect
## FormalEducation FormalEducation
## num_levels
## LearningDataScience 3
## LearningPlatformSelect 5362
## LearningPlatformUsefulnessArxiv 3
## LearningPlatformUsefulnessBlogs 3
## LearningPlatformUsefulnessCollege 3
## LearningPlatformUsefulnessCompany 3
## LearningPlatformUsefulnessConferences 3
## LearningPlatformUsefulnessFriends 3
## LearningPlatformUsefulnessKaggle 3
## LearningPlatformUsefulnessNewsletters 3
## LearningPlatformUsefulnessCommunities 3
## LearningPlatformUsefulnessDocumentation 3
## LearningPlatformUsefulnessCourses 3
## LearningPlatformUsefulnessProjects 3
## LearningPlatformUsefulnessPodcasts 3
## LearningPlatformUsefulnessSO 3
## LearningPlatformUsefulnessTextbook 3
## LearningPlatformUsefulnessTradeBook 3
## LearningPlatformUsefulnessTutoring 3
## LearningPlatformUsefulnessYouTube 3
## LearningDataScienceTime 6
## LearningCategorySelftTaught 0
## LearningCategoryOnlineCourses 0
## LearningCategoryWork 0
## LearningCategoryUniversity 0
## LearningCategoryKaggle 0
## LearningCategoryOther 0
## Age 0
## EmploymentStatus 7
## CurrentJobTitleSelect 16
## MLMethodNextYearSelect 25
## FormalEducation 7
# 1.2
top5_levels <- factor_levels %>%
arrange(desc(num_levels)) %>%
head(5)
# 1.2
print(top5_levels)
## variable num_levels
## LearningPlatformSelect LearningPlatformSelect 5362
## MLMethodNextYearSelect MLMethodNextYearSelect 25
## CurrentJobTitleSelect CurrentJobTitleSelect 16
## EmploymentStatus EmploymentStatus 7
## FormalEducation FormalEducation 7
# 1.3
current_job_levels <- factor_levels %>%
filter(variable == "CurrentJobTitleSelect")
# 1.3
print(current_job_levels)
## variable num_levels
## CurrentJobTitleSelect CurrentJobTitleSelect 16
# 1.4
current_job_levels <- factor_levels %>%
filter(variable == "CurrentJobTitleSelect")
print(current_job_levels)
## variable num_levels
## CurrentJobTitleSelect CurrentJobTitleSelect 16
library('ggplot2')
employer_industry_plot <- ggplot(multipleChoiceResponses, aes(x = EmployerIndustry)) +
geom_bar() +
coord_flip()
print(employer_industry_plot)
#2.1
library('ggplot2')
employer_industry_plot <- ggplot(multipleChoiceResponses, aes(x = EmployerIndustry)) +
geom_bar(stat = "count") +
coord_flip()
print(employer_industry_plot)
#2.2
library('ggplot2')
filtered_responses <- na.omit(multipleChoiceResponses[c("Age", "EmployerIndustry")])
filtered_plot <- ggplot(filtered_responses, aes(x = EmployerIndustry)) +
geom_bar(stat = "count") +
coord_flip()
print(filtered_plot)
#2.3
library(ggplot2)
filtered_responses <- na.omit(multipleChoiceResponses[c("Age", "EmployerIndustry")])
ordered_plot <- ggplot(filtered_responses, aes(x = reorder(EmployerIndustry, -table(EmployerIndustry)[EmployerIndustry]), y = Age)) +
geom_segment(aes(xend = reorder(EmployerIndustry, -table(EmployerIndustry)[EmployerIndustry]), yend = 0), size = 1) +
coord_flip()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
#3
work_levels <- levels(multipleChoiceResponses$WorkInternalVsExternalTools)
custom_order <- c(
"Entirely internal",
"More internal than external",
"Approximately half internal and half external",
"More external than internal",
"Entirely external",
"Do not know"
)
multipleChoiceResponses$WorkInternalVsExternalTools <- factor(
multipleChoiceResponses$WorkInternalVsExternalTools,
levels = custom_order
)
work_plot <- ggplot(multipleChoiceResponses, aes(x = WorkInternalVsExternalTools)) +
geom_bar(stat = "count") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
print(work_plot)
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.