Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 行为图或动作图脚本_R_Graph - Fatal编程技术网

R 行为图或动作图脚本

R 行为图或动作图脚本,r,graph,R,Graph,我试图在R中构建一个行为图或动作图。我已经测量了150秒以上的一个行为(分辨率为1秒),其中我在excel中记录了以下内容:空单元格表示“无行为”,包含1的单元格表示“行为”。每只动物代表一行(150个细胞长),每个实验中得分的动物数量不同(n在11到20之间)。到目前为止,我已经将所有原始数据导出为*.csv 以下是前四行的示例,其中包含一个*.csv文件中的每个~40个数据点(每行为1个动物,每个数据点以逗号分隔): 我想在R中创建一个类似于图7C中所示的图:(整个免费文章在这里:)。随着时

我试图在R中构建一个行为图或动作图。我已经测量了150秒以上的一个行为(分辨率为1秒),其中我在excel中记录了以下内容:空单元格表示“无行为”,包含1的单元格表示“行为”。每只动物代表一行(150个细胞长),每个实验中得分的动物数量不同(n在11到20之间)。到目前为止,我已经将所有原始数据导出为*.csv

以下是前四行的示例,其中包含一个*.csv文件中的每个~40个数据点(每行为1个动物,每个数据点以逗号分隔):

我想在R中创建一个类似于图7C中所示的图:(整个免费文章在这里:)。随着时间的推移,这种行为将被绘制成“小盒子”(稍后在illustrator中可以更改颜色)。从一个*csv文件中创建每个图形会很好(实验)


谁能帮助我?

以下是使用函数的可能解决方案:

# custom function using image to emulate an ethograph
ethograph <- function(zeroOneMatrix, color='blue',xlab='behaviour',ylab='animals'){
  m <- as.matrix(zeroOneMatrix)
  m[m == 0] <- NA
  nAnimals <- nrow(m)
  nTimeSlots <- ncol(m)

  image(x=1:nTimeSlots,
        y=1:nAnimals,
        z=t(m[nAnimals:1,]),
        col=c(color),
        xlab=xlab,
        ylab=ylab,
        yaxt = 'n')
}

# here we create a random matrix of 0 and 1 (animals on the rows and time slots on columns)
# of course you will get your data reading the csv
set.seed(123)
nTimeSlots <- 150
nAnimals <- 50
csv1 <- matrix(sample(0:1,nTimeSlots*nAnimals,replace=TRUE),nrow=nAnimals)

# let's plot
ethograph(csv1, color='blue')
#使用图像模拟行为图的自定义函数

ethograph您能提供一个示例输入数据用于生成该图吗?(原稿的一小部分就可以了)谢谢你的提问,我更新了上面的部分!您希望每个csv都有一个绘图还是一个包含所有csv文件数据的单一绘图(如您提供的示例图像7c所示)?我认为将每个csv转换为一个绘图是可以的。我想在最终导出图形时,我可以将它们放在llustrator中!让我试一试,看看它是如何工作的。我真的很感谢你的支持!
# custom function using image to emulate an ethograph
ethograph <- function(zeroOneMatrix, color='blue',xlab='behaviour',ylab='animals'){
  m <- as.matrix(zeroOneMatrix)
  m[m == 0] <- NA
  nAnimals <- nrow(m)
  nTimeSlots <- ncol(m)

  image(x=1:nTimeSlots,
        y=1:nAnimals,
        z=t(m[nAnimals:1,]),
        col=c(color),
        xlab=xlab,
        ylab=ylab,
        yaxt = 'n')
}

# here we create a random matrix of 0 and 1 (animals on the rows and time slots on columns)
# of course you will get your data reading the csv
set.seed(123)
nTimeSlots <- 150
nAnimals <- 50
csv1 <- matrix(sample(0:1,nTimeSlots*nAnimals,replace=TRUE),nrow=nAnimals)

# let's plot
ethograph(csv1, color='blue')