我有一个虚拟变量(固定或不固定),并希望在图中将其显示为3个独立变量(对象,掩码和长度)的函数。因此,我想将其转换为固定概率。 我找到了以下代码:
data_fix_figs = Target2_all %>%
group_by(Subject, length, mask)%>%
summarise(perc_fixated = mean(Target2_all$Fix) * 100) %>%
ungroup() %>%
Fixation.plot = ggplot(data_fix_figs, aes(x = length, y = perc_fixated,
fill = mask)) +
geom_boxplot() +
ylim(0, 100) +
geom_hline(yintercept = 50)
很遗憾,它无法正常工作。出现此错误:
Error in ggplot(data_fix_figs, aes(x = length, y = perc_fixated, fill =
mask)) : object 'data_fix_figs' not found
更新2
dput(head(Target2_all2 ,20))
structure(list(Subject = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "12", "13", "14",
"15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25",
"26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36",
"37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47",
"48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58",
"59", "60", "61", "62", "63", "64"), class = "factor"), Trialnum = structure(1:20, .Label = c("5",
"7", "9", "11", "13", "15", "17", "19", "21", "23", "25", "27",
"29", "31", "33", "35", "37", "39", "41", "43", "47", "49", "51",
"53", "55", "57", "59", "61", "63", "65", "67", "69", "71", "73",
"75", "77", "79", "81", "83", "85", "87", "89", "91", "93", "95",
"97", "99", "101", "103", "105", "107", "109", "111", "113",
"115", "117", "119", "121", "123", "125", "127", "129", "131",
"133", "135", "137", "139", "141", "143", "145", "147", "149",
"151", "155", "157", "159", "161", "163", "165", "167", "169",
"171"), class = "factor"), length = structure(c(1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L
), .Label = c("4", "6"), class = "factor"), mask = structure(c(2L,
1L, 2L, 3L, 1L, 2L, 3L, 2L, 1L, 3L, 3L, 3L, 2L, 1L, 2L, 3L, 2L,
2L, 3L, 3L), .Label = c("1", "2", "3"), class = "factor"), mask2 = c(2,
1, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2), PreGazeDur = c(171L,
159L, 185L, 302L, 287L, 165L, 116L, 202L, 190L, 348L, 287L, 238L,
178L, 189L, 149L, 228L, 245L, 220L, 167L, 288L), TargDist = structure(c(1L,
1L, 2L, 1L, NA, 2L, 2L, 2L, NA, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 2L,
1L, 1L, 2L), .Label = c("1", "2"), class = "factor"), Fix = c(1L,
1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L), GazeDur = c(311L, 353L, 147L, 257L, NA, 153L, 203L,
156L, NA, 207L, 241L, 309L, 198L, 278L, 161L, 221L, 191L, 188L,
283L, 113L), logGazeDur = c(5.73979291217923, 5.8664680569333,
4.99043258677874, 5.54907608489522, NA, 5.03043792139244, 5.31320597904179,
5.04985600724954, NA, 5.33271879326537, 5.48479693349065, 5.73334127689775,
5.28826703069454, 5.62762111369064, 5.08140436498446, 5.39816270151775,
5.25227342804663, 5.23644196282995, 5.64544689764324, 4.72738781871234
), FixDur = c(161L, 207L, 147L, 257L, NA, 153L, 203L, 156L, NA,
207L, 241L, 164L, 198L, 151L, 161L, 221L, 191L, 188L, 147L, 113L
), logFixDur = c(5.08140436498446, 5.33271879326537, 4.99043258677874,
5.54907608489522, NA, 5.03043792139244, 5.31320597904179, 5.04985600724954,
NA, 5.33271879326537, 5.48479693349065, 5.0998664278242, 5.28826703069454,
5.01727983681492, 5.08140436498446, 5.39816270151775, 5.25227342804663,
5.23644196282995, 4.99043258677874, 4.72738781871234), TotalTime = c(311L,
353L, 147L, 257L, NA, 153L, 203L, 156L, NA, 207L, 241L, 309L,
198L, 278L, 161L, 221L, 191L, 188L, 337L, 113L), logTotalTime = c(5.73979291217923,
5.8664680569333, 4.99043258677874, 5.54907608489522, NA, 5.03043792139244,
5.31320597904179, 5.04985600724954, NA, 5.33271879326537, 5.48479693349065,
5.73334127689775, 5.28826703069454, 5.62762111369064, 5.08140436498446,
5.39816270151775, 5.25227342804663, 5.23644196282995, 5.82008293035236,
4.72738781871234)), .Names = c("Subject", "Trialnum", "length",
"mask", "mask2", "PreGazeDur", "TargDist", "Fix", "GazeDur",
"logGazeDur", "FixDur", "logFixDur", "TotalTime", "logTotalTime"
), row.names = c(1L, 3L, 5L, 7L, 9L, 11L, 13L, 15L, 17L, 19L,
21L, 23L, 25L, 27L, 29L, 31L, 33L, 35L, 37L, 39L), class = "data.frame")