我想为一组箱图添加动态标签

时间:2016-03-30 05:39:53

标签: r boxplot

请原谅我这个问题的邋iness,因为我是品牌spankin'新的堆栈溢出。

所以基本上我想在我在R中设置的箱形图系统中添加标签。这些是使用眼动追踪数据,根据固定屏幕上的x和y位置记录眼睛焦点。

enter image description here

在上面的示例中,我想在每个箱形图旁边放一个数字,表示该人花在不看屏幕上的时间,导致数据丢失。我希望它看起来像这样:

enter image description here

到目前为止,我已成功使用了manipulate和ggplot2,但我似乎无法找到适合我特定需求的方法。我将向您展示一个极小的数据集,让您了解我正在使用的内容:

Subject    Time    Drive    Stimuli    GazeX    GazeY
1          526.10  6        E2         719.1975 696.4445
1          526.12  6        E2         717.1129 696.6486
6          530.83  5        A          716.9166 913.4790
6          530.85  5        A          716.9121 913.6028
10         631.55  6        N3         698.2593 573.6330
10         631.56  6        N3         710.7646 581.1820
16         0.1500  4        N          698.2593 573.6330
16         0.1667  4        N          710.7646 581.1820
25         128.08  7        T1         688.7745 634.5504
25         128.10  7        T1         690.3805 635.9002
40         783.92  5        N2         1178.798 248.8600
40         783.93  5        N2         NA       NA

对于这段代码,它基本上是对8个不同箱图的操纵

par(mfcol=c(2,4))

manipulate(
  c(
#Create a boxplot based off a drive value of 4 following the x-coordinates
  boxplot(
  formula = value ~ Stimuli,
  data    = dat.x4,
  outline = FALSE,
  boxwex  = 0.25,
  #subctr is a picker object in manipulate that filters the data based on the selected subject number
  subset  = c(Subject == subctr & Drive == "4"),
  main    = paste("T0",subctr," 4LD1 X-Position",sep=""),
  xlab    = "Stimuli",
  ylab    = "X-position Gaze"),

#Create a boxplot based off a drive value of 4 following the y-coordinates
  boxplot(
  formula = value ~ Stimuli,
  data    = dat.y4,
  outline = FALSE,
  boxwex  = 0.25,
  subset  = c(Subject == subctr & Drive == "4"),
  main    = paste("T0",subctr," 4LD1 Y-Position",sep=""),
  xlab    = "Stimuli",
  ylab    = "Y-position Gaze"),

  boxplot(#Same as above, for Drive value of 5, following x-coordinates),

  boxplot(#Same as above, for Drive value of 5, following y-coordinates),

  boxplot(#Same as above, for Drive value of 6, following x-coordinates),

  boxplot(#Same as above, for Drive value of 6, following y-coordinates),

  boxplot(#Same as above, for Drive value of 7, following x-coordinates),

  boxplot(#Same as above, for Drive value of 7, following y-coordinates))

我需要代码来保持这个动态选择器的东西,因为我有25个不同的主题,超过400万行数据。这意味着我有25个不同的箱形图系统,就像我链接的那个,都是动态操纵的。

另外,如果您对dat.x4或类似行感到困惑,我将包括我如何使用数据。请记住,我工作了几天试图找到一种方法使箱形图看起来像我需要它们的样子,所以虽然我愿意提出改善这种肮脏的建议,但我确实需要将数据安排得像它是或至少非常相似。

library(reshape)
my.data <- read.csv("gazecsv1.csv", na.strings = "NaN") 
my.data <- gazecsv1

#This is repeated 8 times to have enough different data sets to  show the data I need shown in each boxplot.
dat.x4 <- melt(my.data,id.vars=c("Drive", "Stimuli", "Subject"), measure.vars="GazeX")
dat.x4$Stimuli = factor(dat.x4$Stimuli, c("N"))

0 个答案:

没有答案