![](/img/trans.png)
[英]How to plot a line connecting geom_points for repeated measures in R?
[英]Plot repeated measures of accuracy in R
我有一個包含 80 個項目的 40 個二進制(准確性)度量的 data.frame。 此外,這 80 個項目屬於一個類別(條件)的兩個不同級別(A 和 V)。 我將准確度列轉換為數值變量,以便對其執行算術運算。 我的數據看起來像這樣:
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))
我想要一個散點圖或其他類型的 plot 讓我可以查看每個條件下每個項目的平均分數。 我的想法是在 x 軸上擁有所有 80 個項目,在 y 軸上具有平均精度,並且根據條件為每個項目提供不同的 colors。
我不知道如何 plot plot 中每個項目的平均准確度。 任何幫助表示贊賞。
這是一種方法,盡管我認為 80 個項目可能太多而無法在一個軸上擁有,因為它使 plot 難以閱讀:
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))
如果您考慮 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))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.