我正在绘制每个受试者在两个块(A块和B块)中对“相同”或“不同”刺激做出反应的比例,这意味着每个受试者有4个数据点被绘制。其中A块有两个数据点(相同和不同),B块也是如此。这也意味着有4行数据,每行数据包含每个受试者的反应比例。
我希望在每个块内连接每个受试者的“相同”和“不同”数据点(例如,在A块内通过线连接其一个“相同”的数据点和“不同”的数据点,在B块内也是如此)。
我尝试使用geom_line()中的“group = subject”,但它连接了所有受试者的数据点,而我只想连接每个块内的数据点。
testplot <- ggplot(df, aes(x=block, y=prop, shape=con, colour=con)) +
geom_point(position=position_dodge(width=.1)) +
xlab("Block") + ylab("Prop of responses") +
theme_bw(base_size = 13) +
theme(legend.position="top")
plot(testplot)
样本数据集:
subj = c(1, 1, 2, 2, 3, 3, 4, 4, 1, 1, 2, 2, 3, 3, 4, 4)
prop = c(0.5, 0.8, 0.3, 0.7, 0.9, 0.4, 0.1, 0.5, 1, 0.5, 0.9, 0.2, 0.7, 0.4, 0.8, 0.1)
con = c("same", "same", "same", "same", "same", "same", "same", "same", "diff", "diff", "diff", "diff", "diff", "diff", "diff", "diff")
block = c("A", "B", "A", "B", "A", "B", "A", "B", "A", "B", "A", "B", "A", "B", "A", "B")
df = data.frame(subj, prop, con, block)
我希望这有道理,这可行吗?非常感谢任何帮助!
con
的注意。此外,符号之间的差异可能不太清楚。 - Ian Campbell