简体   繁体   中英

Plot repeated measures of accuracy in R

I have a data.frame containing 40 binary (accuracy) measures of 80 items. Furthermore, the 80 items belong to two different levels (A and V) of a category (condition). I turned the accuracy column into a numeric variable so that I can perform arithmetic operations on it. My Data would look something like this:

Item <- rep(1:80,40)
Condition <- rep(rep(c("A","V"),each=40),40)
accuracyV <- rbinom(1600, size = 1,prob = 0.8)
accuracyA <- rbinom(1600, size = 1,prob = 0.3)
Accuracy <- c(accuracyA,accuracyV)
MyData <- data.frame(Item,Condition,Accuracy)
MyData$Item <- as.factor(MyData$Item)
MyData$Accuracy <- as.numeric(as.character(MyData$Accuracy))

I would like to have a scatterplot or some other type of plot that allows me to see the average score of each item per condition. My idea would be to have all 80 items in the x axis, with average accuracy on the y axis, and different colors for each item depending on condition.

I am at a loss on how to plot average accuracy per item in the plot. Any help is appreciated.

Here's one way to do it, though I think that 80 items is perhaps too many to have on a single axis, as it makes the plot difficult to read:

library(dplyr)
library(ggplot2)

MyData %>% 
  group_by(Item, Condition) %>% 
  summarize(Accuracy = mean(Accuracy)) %>% 
  ggplot(aes(x = Item, y = Accuracy, fill = Condition)) + 
  geom_col() +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

在此处输入图像描述

It may be a bit clearer if you facet the plot:

MyData %>% 
  group_by(Item, Condition) %>% 
  summarize(Accuracy = mean(Accuracy)) %>% 
  ggplot(aes(x = Item, y = Accuracy, fill = Condition)) + 
  geom_col() +
  facet_wrap(.~Condition, nrow = 2, ncol = 1, scales = "free") +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM