I have database of ratings with 16937 rows and 4 variables:
1.Subject
2.Distance_from_trap_F
3.type
4.rate
Here are the first 50 rows:
structure(list(Subject = c(110L, 110L, 110L, 110L, 110L, 110L,
110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L,
110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L,
110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L,
110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L
), type = structure(c(1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L,
1L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L,
1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L), levels = c("Affective Valence",
"Semantic Valence"), class = "factor"), rate = c(25L, 14L, 8L,
0L, 17L, 0L, 16L, 0L, 16L, 3L, 22L, 24L, 24L, 14L, 1L, 0L, 6L,
22L, 21L, 18L, 13L, 19L, 21L, 5L, 12L, 1L, 22L, 20L, 24L, 0L,
6L, 3L, 11L, 15L, 15L, 13L, 20L, 15L, 31L, 0L, 20L, 7L, 33L,
15L, 28L, 28L, 12L, 7L, 0L, 13L), Distance_from_trap_F = structure(c(3L,
4L, 1L, 1L, 3L, 1L, 2L, 1L, 2L, 1L, 4L, 4L, 2L, 2L, 1L, 1L, 2L,
2L, 4L, 3L, 4L, 3L, 4L, 2L, 1L, 1L, 4L, 4L, 4L, 1L, 2L, 1L, 2L,
2L, 3L, 3L, 4L, 3L, 4L, 1L, 3L, 2L, 4L, 3L, 4L, 4L, 2L, 2L, 1L,
3L), levels = c("0", "1", "2", "3"), class = "factor")), row.names = c(NA,
50L), class = "data.frame")
I built a graph in ggplot2
with facet_wrap
, according to the type variable (two levels: Affective Valence/Semantic Valence).
I wanted to add different text to the two parts of the graph.
I tried using:
Graph_data_text <- data.frame(label = c("good","n.s"),
group = names(table(Mid_Maze$type)))
and then in the ggplot2:
geom_text(data=Graph_data_text,x=3.5, y=22, aes(label = label),family="sans",size=3,inherit.aes=FALSE)
The problem is I want "good" to appear in the left panel (Affective Valence) and "n.s" in the right panel (Semantic Valence) but currently both the "good" and the "n.s" appear in both panels.
The full code I used for the graph:
H2_Mid_graph <- Mid_Maze%>%group_by(Subject,Distance_from_trap_F,type )%>%dplyr::summarise(rate=mean(rate))%>% ggplot(aes(x=Distance_from_trap_F,y=rate,fill=Distance_from_trap_F))+facet_wrap(~type)+ geom_violin(trim=TRUE,position=position_dodge(width=0.75),width=1.0,show.legend = FALSE)+geom_text(data=Graph_data_text,x=3.5, y=22, aes(label = label),family="sans",size=3,inherit.aes=FALSE)