Я пытаюсь создать график, используя r, на котором есть несколько прямоугольников на одном графике. Однако когда я запускаю этот блок кода, я получаю только один боксплот, а не другой 11. Я пробовал ggplot и продолжаю получать ошибки, а также принимаю только два «ответа». Ниже приведен код, с которым я работаю:
Are people with dependents judged more reckless than people without dependents, even when they do the same activity?
# #Dependents vs no dependents in the sport and their associated risk - climbing
# #------------------------------------------------------------------
ans1F <-sportrisks %>%
filter(sport=="climbing")%>%
filter(dependents=="TRUE")%>%
select("dependents","recklessness")
ans1F
ans1M <-sportrisks %>%
filter(sport=="climbing")%>%
filter(dependents=="FALSE")%>%
select("recklessness","dependents")
ans1M
#dependents vs no dependents in the sport and their associated risk - golf
#--------------------------------------------------------------
ans2F <-sportrisks %>%
filter(sport=="golf")%>%
filter(dependents=="TRUE")%>%
select("recklessness","dependents")
ans2F
ans2M <-sportrisks %>%
filter(sport=="golf")%>%
filter(dependents=="FALSE")%>%
select("recklessness","dependents")
ans2M
#Dependents vs no dependents in the sport and their associated risk - running
#-----------------------------------------------------------------
ans3F <-sportrisks %>%
filter(sport=="running")%>%
filter(dependents=="TRUE")%>%
select("recklessness","dependents")
ans3F
ans3M <-sportrisks %>%
filter(sport=="running")%>%
filter(dependents=="FALSE")%>%
select("recklessness","dependents")
ans3M
#dependents vs no dependents in the sport and their associated risk - skitouring
#--------------------------------------------------------------------
ans4F <-sportrisks %>%
filter(sport=="skitouring")%>%
filter(dependents=="TRUE")%>%
select("recklessness","dependents")
ans4F
ans4M <-sportrisks %>%
filter(sport=="skitouring")%>%
filter(dependents=="FALSE")%>%
select("recklessness","dependents")
ans4M
#Dependents vs no depenents in the sport and their associated risk - surfing
#-----------------------------------------------------------------
ans5F <-sportrisks %>%
filter(sport=="surfing")%>%
filter(dependents=="TRUE")%>%
select("recklessness","dependents")
ans5F
ans5M <-sportrisks %>%
filter(sport=="surfing")%>%
filter(dependents=="FALSE")%>%
select("recklessness","dependents")
ans5M
# #dependents vs no dependents in the sport and their associated risk - hillwalking
# #---------------------------------------------------------------------
ans6F <-sportrisks %>%
filter(sport=="hillwalking")%>%
filter(dependents=="TRUE")%>%
select("recklessness","dependents")
ans6F
ans6M <-sportrisks %>%
filter(sport=="hillwalking")%>%
filter(dependents=="FALSE")%>%
select("recklessness","extreme_risk")
ans6M
boxplot(c(ans1F$recklessness,ans1M$recklessness, ans2F$recklessness, ans2M$recklessness,ans3M$recklessness,ans3F$recklessness,ans4F$recklessness, ans4M$recklessness, ans5F$recklessness, ans5M$recklessness,ans6M$recklessness,ans6F$recklessness),
main = "Multiple boxplots for comparision",
las = 2,
col = c("pink","blue"),
border = "brown",
horizontal = FALSE,
ylim = c(0,100)
)
Вот структура данных:
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 2060 obs. of 27 variables:
$ Q1 : num 1 1 1 1 1 1 1 1 1 1 ...
$ Q3 : num 1 1 3 1 1 2 1 2 1 2 ...
$ Q4 : num 4 2 1 2 2 1 2 2 4 2 ...
$ Q5 : num NA NA NA NA NA NA NA NA NA NA ...
$ Dangerous : num 3 4 2 6 5 2 3 5 3 3 ...
$ Q5_a : num NA NA NA NA NA NA NA NA NA NA ...
$ Judgement : num 3 4 5 3 3 5 4 4 3 3 ...
$ Q6 : num NA NA NA NA NA NA NA NA NA NA ...
$ recklessness : num 1 3 2 8 9 1 2 3 3 4 ...
$ Q6_a : num NA NA NA NA NA NA NA NA NA NA ...
$ Q6_a_1 : num 4 4 4 4 5 5 4 4 3 3 ...
$ Q7 : num 2 1 2 2 1 2 1 1 1 1 ...
$ Insurance_premium: num NA 25 NA NA 150 NA 100 200 100 150 ...
$ Q8_1 : num 0 0 0 0 0 1 1 1 1 0 ...
$ Q8_2 : num 0 0 0 0 0 1 0 0 0 0 ...
$ Q8_3 : num 0 0 0 0 0 0 0 0 0 0 ...
$ Q8_4 : num 0 0 0 0 0 1 0 0 0 0 ...
$ Q8_5 : num 0 0 0 0 0 0 0 0 0 0 ...
$ Q8_6 : num 1 1 1 1 1 0 0 0 0 1 ...
$ Q8_7 : num 0 0 0 0 0 0 0 0 0 0 ...
$ sport : chr "climbing" "climbing" "climbing" "climbing" ...
$ gender : chr "male" "male" "male" "male" ...
$ dependents : logi FALSE FALSE FALSE FALSE FALSE FALSE ...
$ charity : logi FALSE FALSE FALSE FALSE FALSE FALSE ...
$ low_competence : logi FALSE FALSE FALSE FALSE FALSE FALSE ...
$ guide : logi FALSE FALSE FALSE FALSE FALSE FALSE ...
$ extreme_risk : logi FALSE FALSE FALSE FALSE FALSE FALSE ...