G
I made some changes to your code.I changed the name of the variables df2 For Q.1, Q.2, Q.3, Q.4 and Q.5.In long2 I called the variable gabarito because it represents the amount of students who have settled their questions, right?After I join long and long2 by ITENS and what you called turma (so I modified the variable names in df2). Follow code and result:ITENS <-c("A","B","C","D","E")
Q.1 <-c(10,20,10,40,10); Q.2 <-c(5,25,0,50,10); Q.3 <-c(15,20,5,40,10)
Q.4 <-c(15,30,5,30,5); Q.5 <-c(20,25,5,20,15); Q.6 <-c(10,20,10,40,10)
df <- data.frame(ITENS,Q.1,Q.2,Q.3,Q.4,Q.5,Q.6)
Q.1 <-c(0,20,0,0,0); Q.2 <-c(5,0,0,0,0); Q.3 <-c(0,0,5,0,0)
Q.4 <-c(0,0,0,30,0); Q.5 <-c(20,0,0,0,0); Q.6 <-c(0,0,10,0,0)
df2 <- data.frame(ITENS,Q.1,Q.2,Q.3,Q.4,Q.5,Q.6)
library(tidyr)
long <- df %>% gather(turma, quantidade, Q.1:Q.6)
long2 <- df2 %>% gather(turma, gabarito, Q.1:Q.6)
library(dplyr)
l <- left_join(long, long2, by = c("ITENS", "turma"))
ggplot(l, aes(x = ITENS)) +
geom_bar(aes(y = quantidade, fill = "red"), stat = "identity", position = "identity") +
guides(fill = F) +
geom_bar(aes(y = gabarito, fill = "blue"), stat = "identity", position = "identity") +
facet_wrap(~turma)