I'm still new to R and I have a problem with plotting my data which looks similar to this:
set.seed(529)
test <- data.frame(StartPos = rep(1:10, times = 10),
Response = c(sample(c("H", "M", "W"), 50, replace=T),
sample(c("M", "W"), 50, replace = T)),
Velocity = c(sample(c(-36, 36), 100, replace = T)))
head(test)
based on a criteria.
The data consists of 100 rows with the Start Positions from 3-5 and 10-11 ( each randomly generated 10 times (some 20 times like Start Position 3 which could exist 20 times)). Each of the Start Positions also has a answer which could be H for Hit, M for Miss or W for wrong. It's possible that there is no H for a certain Start Position. There is also a column called Velocity with the values -36 and 36 which describe the direction of the Stimlus which started at the certain StartPos (-36 to the right, 36 to the left).
I want to plot the number of Hits on each side (HitR and HitL) for each Start Postion in a barplot (for example 17 Hits out of 20 for StartPos 3, 7 of these are Hits to the right - the other 10 are Hits to the left) - It's similar to my previous post with 1 further condition: ggplot2 alternatives to fill in barplots, occurence of factor in multiple rows
I was able to count the number of Hits. But without the criterion whether it was a hit to the right or the left.
I accomplished that with the following code:
hit_counts <- test %>%
mutate(StartPos = as.factor(StartPos)) %>%
filter(Response == "H") %>%
count(StartPos, .drop = FALSE)
hit_counts
ggplot(hit_counts, aes(x = StartPos,y=n)) +
geom_col()+labs(x="StartPos",y="Hitrate")
The Plot looked like this:
It's close to what I need, but I can't think of a way of how to divide or summarize the Hits based on it's travel Direction and then plot them.