Hello, consider two data frames:
df = the number of students who answered items A, B, C, D and E of a 6-question test
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)
df2 = is the question template
Q.01 <-c(0,20,0,0,0)
Q.02 <-c(5,0,0,0,0)
Q.03 <-c(0,0,5,0,0)
Q.04 <-c(0,0,0,30,0)
Q.05 <-c(20,0,0,0,0)
Q.06 <-c(0,0,10,0,0)
df2 <- data.frame(ITENS,Q.01,Q.02,Q.03,Q.04,Q.05,Q.06)
So I create two dataframes: long and long2
library(tidyr)
long <- df %>% gather(turma, quantidade, Q.1:Q.6)
long2 <- df2 %>% gather(turma, quantidade, Q.01:Q.06)
and plot the graphics of each data frame:
library(ggplot2)
ggplot(long)+geom_bar(aes(x = ITENS, y = quantidade, fill ="red"),stat =
"identity")+facet_wrap(~turma)+guides(fill=FALSE)
ggplot(long2)+geom_bar(aes(x = ITENS, y = quantidade),stat = "identity")+
facet_wrap(~turma) +guides(fill=FALSE)
The graphics are on separate pages, the idea was to overlap those two graphs . In such a way that in the graph of the amount of students that reponderated the items appeared the template of the question in red.
I have tried various ways of presenting the solutions presented here here and < a href="https://en.stackoverflow.com/questions/85844/sobrepor-gr%C3%A1fico-no-r"> here , but without success.
I can even overlap, but then I would have to do one chart at a time:
ggplot(data = data.frame(a = Q.1, b = Q.01, x = df$ITENS)) + geom_bar(aes(x =
x, y = Q.1 , fill = "red"),stat = "identity") + geom_bar(aes(x = x, y = Q.01,
fill= "blue"),stat = "identity")
Att.