请有人能帮助我绘制数据所需的R代码吗?我一直在努力工作几个小时,在网上搜索,我真的很挣扎。
这是我将数据放入R Studio中的表/矩阵的示例:
Percentage Correct
4 71.88
20 65.80
40 63.92
60 63.47
4
,20
,40
和60
是分类变量 - 它们代表不同级别的分类干扰。
Percentage Correct
是参与者对每个干扰级别都正确的图像百分比。
例如,63.47
表示当干扰类别为60时,所有参与者的正确回答的平均百分比为63.47%。
下面我附上了一些我想要实现的图形图像。我不一定希望我的那种复杂,但就像基本风格一样。
我正在努力实际绘制任何内容,而不会出现任何错误。
非常感谢任何帮助,非常感谢!
答案 0 :(得分:1)
以下是使用ggplot2
开始的可能性:
# Your sample data
df <- read.table(text =
"x y
4 71.88
20 65.80
40 63.92
60 63.47", header = T);
library(ggplot2);
ggplot(df, aes(as.factor(x), y)) +
geom_point() +
labs(y = "Percentage correct", x = "Categorical variable");
如果您将x
变为factor
,则会将其视为分类变量。
或作为条形图(由@neilfws建议):
library(ggplot2);
ggplot(df, aes(as.factor(x), y)) +
geom_bar(stat = "identity") +
labs(y = "Percentage correct", x = "Categorical variable");