Construct a bar graph for the given data below.
# install.packages("tidyverse")
library(tidyverse)
## Warning: package 'lubridate' was built under R version 4.5.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.1 ✔ stringr 1.5.2
## ✔ ggplot2 4.0.0 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── 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
q1_data <- data.frame(Color = c("red","orange","green","gray","purple","yellow"),
Number = c(4,3,4,1,6,2))
ggplot(q1_data,aes(x = factor(Color),y = Number)) +
geom_col() +
scale_fill_identity() +
labs(title = "Sample Data",
x = "Color",
y = "Number") +
theme_gray()
Which of the following is a factor of 315?
A. 8
B. 9
C. 10
D. 11
# install.packages("tidyverse")
library(tidyverse)
q2_data <- data.frame(Choice = LETTERS[1:4],
Number = 8:11)
correct_answer <- q2_data %>%
mutate(Factor = 315 %% Number == 0) %>%
filter(Factor == TRUE) %>%
pull(Choice)
cat("The correct answer is:",correct_answer,"\n")
## The correct answer is: B
For a group of seven people, what are the chances that any of them celebrate their birthday on the same day of the week?
set.seed(123) # for reproducibility
N <- 1e5 # 100,000 trials
simulation <- replicate(N, {
birthdays <- sample(1:7,size = 7,replace = T) # weekdays 1 to 7
any(duplicated(birthdays))
})
cat("The probability is:",mean(simulation),"\n")
## The probability is: 0.9939