我希望使用 ggplot 和 dplyr 将我的数据百分比 yes/no 作为每人一个条
I would like to have my data to be percent yes/no as one bar per person using ggplot and dplyr
我可以解释...
所以基本上我想比较每个审阅者的是推荐与否推荐的百分比。不确定如何执行此操作,但我认为每个审阅者与彼此相比的 yes/no 百分比堆叠在一起的条形图是理想的。尽管我很接近,但我很难计算百分比以及制定情节本身。任何替代方案也将受到欢迎!
数据
structure(list(Timestamp = structure(c(1542404919, 1542405223,
1542405732, 1542406107, 1542406389, 1542406809, 1542407115, 1542407462,
1542407858, 1542638598, 1542639521, 1542639522, 1542639536, 1542639885,
1542640508, 1542640795, 1542641705, 1542642212, 1542705890, 1542706366
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), Reviewer = c("Dan Wright",
"A", "A", "A", "B", "D",
"C", "C", "D", "D", "E",
"B", "C", "D", "B",
"E", "E", "E", "B",
"A"), `Applicant Name:` = c("Mco", "Kai",
"Shan", "Ken", "Clea", "Roha",
"Ian", "Alex", "Kath", "Evan",
"Jerr", "Beth", "Bria", "Hele",
"Fred", "Sara", "Irma", "Alee",
"Jerr", "Sara"), `Resume Score:` = c(4, 5, 5,
3, 3, 5, 4, 4, 2, 4, 5, 5, 4, 5, 4, 5, 4, 4, 4, 4), `Cover Letter- Motivation Score:` = c(8,
10, 7, 8, 9, 9, 7, 8, 8, 8, 9, 7, 6, 10, 5, 7, 7, 9, 5, 7), `Cover Letter- Strengths Score:` = c(7,
8, 6, 7, 10, 7, 5, 7, 5, 6, 9, 5, 6, 10, 6, 4, 6, 8, 7, 8), `Cover Letter- Experiences Score:` = c(9,
9, 8, 7, 8, 8, 8, 7, 8, 6, 9, 5, 5, 10, 6, 6, 7, 7, 7, 8), `Short Answer Question #1:` = c(7,
8, 5, 8, 6, 5, 7, 6, 9, 7, 9, 8, 7, 10, 6, 9, 8, 8, 8, 8), `Short Answer Question #2:` = c(6,
9, 9, 7, 6, 8, 6, 10, 9, 7, 7, 8, 4, 10, 6, 10, 7, 8, 8, 9),
`Short Answer Question #3:` = c(9, 6, 7, 10, 8, 5, 4, 7,
9, 6, 10, 1, 9, 10, 6, 10, 7, 9, 9, 9), Recomdendation = c("No",
"Yes", "No", "No", "No", "Yes", "Yes", "No", "Yes", "Yes",
"No", "No", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes",
"Yes"), `Are there any red flags for this candidate?` = c("None",
"None", "None", "None", "None", "Mentioned potential summer job that he feels would conflict with RA training dates",
"None", "None", "None", "none", "None", "None", "none", "None",
"none", "None", "none", "none", "none", "none")), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))
代码
library(readxl)
library(dplyr)
library(ggplot2)
library(ggthemes)
Apps <- read_excel("C:/Users/johnt/Desktop/Residential Education/RA Selection/Application Workbook.xlsx",
sheet = "Application Review")
View(Apps)
yayy <- Apps %>%
group_by(Reviewer, Recomdendation) %>%
summarize(counts = n())
###TURN ME INTO PERCENTS
ggplot(yayy,aes(x=Reviewer,y=Recomdendation,fill=factor(counts)))+
geom_bar(stat="identity",position="dodge")+
scale_fill_discrete(name="Gender",
breaks=c(1, 2),
labels=c("No", "Yes"))+
xlab("Reviewer")+ylab("Percentage")+ theme_economist() +
theme(axis.text.x = element_text(angle = 90))
简而言之,我想看看每个评论者给出的赞成票的百分比是多少,虽然这是我能想到的最好的方式,但我愿意接受新想法!
编辑:
由@DiceBoyT 解决;现在我想制作一个柱状图但是它不会让我控制我的轴....
reviewers<- Apps %>%
group_by(Reviewer) %>%
summarise(percent_yes = mean(Recommendation == "Yes")) %>%
arrange(desc(percent_yes))
reviewers <-reviewers[-c(24), ]
ggplot(data = reviewers, mapping = aes(x = reorder(Reviewer, -percent_yes), y = percent_yes)) +
geom_col(fill = "steelblue", color = "white")+
scale_y_continuous(limits=c(.5, 1)) +
xlab("Reviewer")+ylab("Percentage") +
theme(axis.text.x = element_text(angle = 90))
这是一种使用 facet_wrap
来按评论者拆分地块的方法:
ggplot(Apps, aes(as.factor(Recomdendation))) +
geom_bar(aes(y = (..count..)/sum(..count..))) +
facet_wrap( ~ Reviewer) +
labs(y = "Percentage")
如果我理解正确的话,这应该会为您提供绘图所需的数据:
Apps %>%
group_by(Reviewer) %>%
summarise(percent_yes = mean(Recomdendation == "Yes"))
#> # A tibble: 6 x 2
#> Reviewer percent_yes
#> <chr> <dbl>
#> 1 A 0.5
#> 2 B 0.5
#> 3 C 0.667
#> 4 D 1
#> 5 Dan Wright 0
#> 6 E 0.75
我可以解释...
所以基本上我想比较每个审阅者的是推荐与否推荐的百分比。不确定如何执行此操作,但我认为每个审阅者与彼此相比的 yes/no 百分比堆叠在一起的条形图是理想的。尽管我很接近,但我很难计算百分比以及制定情节本身。任何替代方案也将受到欢迎!
数据
structure(list(Timestamp = structure(c(1542404919, 1542405223,
1542405732, 1542406107, 1542406389, 1542406809, 1542407115, 1542407462,
1542407858, 1542638598, 1542639521, 1542639522, 1542639536, 1542639885,
1542640508, 1542640795, 1542641705, 1542642212, 1542705890, 1542706366
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), Reviewer = c("Dan Wright",
"A", "A", "A", "B", "D",
"C", "C", "D", "D", "E",
"B", "C", "D", "B",
"E", "E", "E", "B",
"A"), `Applicant Name:` = c("Mco", "Kai",
"Shan", "Ken", "Clea", "Roha",
"Ian", "Alex", "Kath", "Evan",
"Jerr", "Beth", "Bria", "Hele",
"Fred", "Sara", "Irma", "Alee",
"Jerr", "Sara"), `Resume Score:` = c(4, 5, 5,
3, 3, 5, 4, 4, 2, 4, 5, 5, 4, 5, 4, 5, 4, 4, 4, 4), `Cover Letter- Motivation Score:` = c(8,
10, 7, 8, 9, 9, 7, 8, 8, 8, 9, 7, 6, 10, 5, 7, 7, 9, 5, 7), `Cover Letter- Strengths Score:` = c(7,
8, 6, 7, 10, 7, 5, 7, 5, 6, 9, 5, 6, 10, 6, 4, 6, 8, 7, 8), `Cover Letter- Experiences Score:` = c(9,
9, 8, 7, 8, 8, 8, 7, 8, 6, 9, 5, 5, 10, 6, 6, 7, 7, 7, 8), `Short Answer Question #1:` = c(7,
8, 5, 8, 6, 5, 7, 6, 9, 7, 9, 8, 7, 10, 6, 9, 8, 8, 8, 8), `Short Answer Question #2:` = c(6,
9, 9, 7, 6, 8, 6, 10, 9, 7, 7, 8, 4, 10, 6, 10, 7, 8, 8, 9),
`Short Answer Question #3:` = c(9, 6, 7, 10, 8, 5, 4, 7,
9, 6, 10, 1, 9, 10, 6, 10, 7, 9, 9, 9), Recomdendation = c("No",
"Yes", "No", "No", "No", "Yes", "Yes", "No", "Yes", "Yes",
"No", "No", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes",
"Yes"), `Are there any red flags for this candidate?` = c("None",
"None", "None", "None", "None", "Mentioned potential summer job that he feels would conflict with RA training dates",
"None", "None", "None", "none", "None", "None", "none", "None",
"none", "None", "none", "none", "none", "none")), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))
代码
library(readxl)
library(dplyr)
library(ggplot2)
library(ggthemes)
Apps <- read_excel("C:/Users/johnt/Desktop/Residential Education/RA Selection/Application Workbook.xlsx",
sheet = "Application Review")
View(Apps)
yayy <- Apps %>%
group_by(Reviewer, Recomdendation) %>%
summarize(counts = n())
###TURN ME INTO PERCENTS
ggplot(yayy,aes(x=Reviewer,y=Recomdendation,fill=factor(counts)))+
geom_bar(stat="identity",position="dodge")+
scale_fill_discrete(name="Gender",
breaks=c(1, 2),
labels=c("No", "Yes"))+
xlab("Reviewer")+ylab("Percentage")+ theme_economist() +
theme(axis.text.x = element_text(angle = 90))
简而言之,我想看看每个评论者给出的赞成票的百分比是多少,虽然这是我能想到的最好的方式,但我愿意接受新想法!
编辑: 由@DiceBoyT 解决;现在我想制作一个柱状图但是它不会让我控制我的轴....
reviewers<- Apps %>%
group_by(Reviewer) %>%
summarise(percent_yes = mean(Recommendation == "Yes")) %>%
arrange(desc(percent_yes))
reviewers <-reviewers[-c(24), ]
ggplot(data = reviewers, mapping = aes(x = reorder(Reviewer, -percent_yes), y = percent_yes)) +
geom_col(fill = "steelblue", color = "white")+
scale_y_continuous(limits=c(.5, 1)) +
xlab("Reviewer")+ylab("Percentage") +
theme(axis.text.x = element_text(angle = 90))
这是一种使用 facet_wrap
来按评论者拆分地块的方法:
ggplot(Apps, aes(as.factor(Recomdendation))) +
geom_bar(aes(y = (..count..)/sum(..count..))) +
facet_wrap( ~ Reviewer) +
labs(y = "Percentage")
如果我理解正确的话,这应该会为您提供绘图所需的数据:
Apps %>%
group_by(Reviewer) %>%
summarise(percent_yes = mean(Recomdendation == "Yes"))
#> # A tibble: 6 x 2
#> Reviewer percent_yes
#> <chr> <dbl>
#> 1 A 0.5
#> 2 B 0.5
#> 3 C 0.667
#> 4 D 1
#> 5 Dan Wright 0
#> 6 E 0.75