r语言 - unique.default(x, nmax = nmax) 中的错误:unique() 仅适用于 ggplot



当我尝试运行此代码时,标题中出现错误。我是初学者,不明白如何解决它。我已经包含了所有代码以供参考。ggplot 行之前的所有行似乎都有效,但最后一行会导致错误。

ClassStroopData_300 <- read_csv("ClassStroopData_300.csv")
Data300 <-ClassStroopData_300
mean(Data300$responseTime)
sd(Data300$responseTime)
Data300["WorkspaceVar1"] <- grepl("_",Data300$note)
WorkspaceVar1 that contains the info whether or not the column "note" contained a "_"
Data300["WorkspaceVar2"] <- grepl("text",Data300$content)
Data300["WorkspaceVar3"] <-grepl("red_red|blue_blue|green_green|orange_orange|purple_purple",Data300$content)
Data300["WorkspaceVar4"] <- grepl("4db78970c3816d3d|a8cc6a79046e188f|c21c48d74bc99a6|dd2942c485109f3e|5eb0fbeb9b0685e2",Data300$frameId)
Data300["incongruent"] <- Data300$WorkspaceVar1*2
Data300["instructions"] <- Data300$WorkspaceVar2*1
Data300["congruent"] <- Data300$WorkspaceVar3*3
Data300["practice"] <- Data300$WorkspaceVar4*10
Data300["condition sums"] <- Data300$incongruent + Data300$instructions + Data300$congruent + Data300$practice
Data300["condition"] <- factor(Data300$`condition sums`,levels = c("1","2","3","12"),labels = c("instructions","incongruent","congruent","practice"))
CongruentTrials <- subset(Data300, condition == "congruent")
mean(CongruentTrials$responseTime)
sd(CongruentTrials$responseTime)
IncongruentTrials <- subset(Data300, condition == "incongruent")
mean(IncongruentTrials$responseTime)
sd(IncongruentTrials$responseTime)
aggregate(Data300$responseTime,list(Data300$condition),mean)
aggregate(Data300$responseTime,list(Data300$condition),sd)
MICT <- mean(IncongruentTrials$responseTime)
SDICT <- sd(IncongruentTrials$responseTime)
MCT <- mean(CongruentTrials$responseTime)
SDCT <- sd(CongruentTrials$responseTime)
cbind(c(MICT,MCT), c(SDICT,SDCT))
table = cbind(c(MICT,MCT), c(SDICT,SDCT))
colnames(table) = c("mean","standard deviation")
rownames(table) = c("Incongruent", "Congruent")
t.test(IncongruentTrials$responseTime, CongruentTrials$responseTime, paired = T, var.equal = T)
library(ggplot2)
IncongruentNoOutliers <- subset(IncongruentTrials, responseTime < 1267.0660+401.6672*3.5 & responseTime > 1267.0660-401.6672*3.5)
CongruentNoOutliers <- subset(CongruentTrials, responseTime < 1009.4660+352.9656*3.5 & responseTime > 1009.4660-352.9656*3.5)
CongruentNoOutliers$Identify = "Congruent"
IncongruentNoOutliers$Identify = "Incongruent"
AllNoOutliers = rbind(CongruentNoOutliers, IncongruentNoOutliers)
ggplot(AllNoOutliers, aes(x=responseTime, fill=as.factor(identify))) + geom_histogram(alpha = 0.5, position = 'identity') + scale_fill_discrete(name="Trial Type")

我制作了此示例代码来说明您的 ggplot 行没问题:

responseTime <- sample(20:50, 200, TRUE)
identify <- sample(letters[1:2], 200, TRUE)
AllNoOutliers <- data.frame(responseTime, identify, stringsAsFactors = FALSE)
library(ggplot2)
ggplot(AllNoOutliers, aes(x=responseTime, fill=as.factor(identify))) + 
geom_histogram(alpha = 0.5, 
position = 'identity', binwidth = 20) + 
scale_fill_discrete(name="Trial Type") 

检查class(AllNoOutliers$responseTime)是否numeric

最新更新