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!!

Look for all of the spike times that are greater than (=come after) the time

of the start of the trial, minus 1 second AND are less than (=come before) the start # time plus 9 seconds, so a total of 10 seconds.

The & operator checks that both conditions are met.

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

We want to center our plot around the time when the image was shown

We subtract the time of the beginning of the stimulus from every time so that

this becomes time 0

trial <- trial - learnEvents$On[1]

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))

We can now add the rest of the trials.

We start from 2 as we already plotted number 1! for (i in 2:nrow(learnEvents))


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]

The at parameter defines the height at which to plot the points stripchart(trial, pch = 20, add = TRUE, at = i, cex = 0.5)


We plot a rectangle around the time the image was shown

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

 xright = learnEvents$Off[1] - learnEvents$On[1], ytop = nrow(learnEvents),
 col = rgb(0.4, 0.4, 0.4, 0.2), border = NA)!!