 # how to make peri-stimulus histogram (PSTH) in r

I basically want to make a PSTH plot as shown in the attachment. the data is shown in the attachment, I wrote the code below and made a dot graph as shown in attachment, the next I should make the PSTH graph as shown in attachment. the teacher just said I can make this PSTH graph in a very similar way I made the dot graph. but I am confused, I've never made PSTH graph before and don't even understand why the y-axis is with decimals, shouldn't they represent the times of trails so should be integers like 1,2,3,4.. ? would anyone help me with the PSTH plot? it will help a lot, thanks!!

# The & operator checks that both conditions are met.

trial <- times\$Time[times\$Time > (learnEvents\$On - 1) &
times\$Time < (learnEvents\$On + 9)]

# this becomes time 0

trial <- trial - learnEvents\$On

# Plot the action potential times. Note that we specify ylim so that we can # add one line of dots for each trial!

stripchart(trial, pch = 20,
ylim = c(0, nrow(learnEvents)),
main = "Learn",
cex = 0.5, xlim = c(-1, 9))

{

# This is the same as above, but now we are getting event 2, then 3, and so on

trial <- times\$Time[times\$Time>(learnEvents\$On[i] - 1) &
times\$Time<(learnEvents\$On[i] + 9)]

# Note that we always subtract the time of the first event!

trial <- trial - learnEvents\$On[i]

}

# rgb specifies a colour as red, green, blue and transparency (from 0 to 1) rect(xleft = 0, ybottom = 0,

`````` xright = learnEvents\$Off - learnEvents\$On, ytop = nrow(learnEvents),
col = rgb(0.4, 0.4, 0.4, 0.2), border = NA)!!
``````