graph - R ethogram or actogram script -


i trying build ethogram or actogram figure in r. measured single behavior on 150 seconds (with 1 sec resolution), in wrote down following in excel: empty cell represents "no behavior", , cell containing 1 represents "behavior". each animal represents 1 row (150 cells long), , number of animals scored different in each experiment (n between 11 , 20). far, have raw data exported *.csv

here's example of first 4 rows containing each ~40 data points 1 *.csv file (each row 1 animal, each data point comma separated):

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1,1,1,1,1,1,1  ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1,1,1,1,1,1,  ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,,,,,,1,1,1,,,,  ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,,1,1,1,1,1,,,, 

i create graph in r looking similar 1 in figure 7c shown here: https://elife-publishing-cdn.s3.amazonaws.com/08758/elife-08758-fig7-v2.jpg (the whole, free article here: https://elifesciences.org/content/4/e08758). behavior plotted "tiny boxes" on time (coloring changed later in illustrator). , nice create each 1 graph 1 *csv file (experiment).

who can me?

here's possible solution using image() function :

# custom function using image emulate 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 create random matrix of 0 , 1 (animals on rows , time slots on columns) # of course data reading 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') 

result:

enter image description here


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -