ggpmisc

39 views
Skip to first unread message

neilsrini

unread,
Aug 24, 2016, 2:17:00 PM8/24/16
to ggplot2
Hi I am using

ggpmisc to look for peaks in time series data. 

It is a biosignal dataset. 


I use something like.....

p<- ggplot(data, aes(x=time, y=V2.)) + geom_line()

p2<- p + stat_peaks(colour = "blue", span = 21, ignore_threshold = 0.8) 

p2


p3<- p2 +  stat_peaks(geom = "text", colour = "red", span = 21, ignore_threshold = 0.8,
                                                                              hjust = -0.1, angle = 90) 

p3

p4<- p3 +stat_valleys(colour = "green", span = 59, ignore_threshold = 0.3)



to get the points I want which I can visually see and am happy with 

looks like the attached file. 


Does anyone know how to get the values of these markers, other than copying the text on the graph and putting them into a CSV file?

I have over 100 such files to analyse, and then I want to do some R maths on the CSV files ie. for each file subtract the high blue peaks from the lower ones, and the time from lower blue peak to green etc etc etc. So I really need the time stamps of these dots.


Any help 
Most Welcome

BW
Neil
Rplot01.pdf

Pete St Marie

unread,
Aug 24, 2016, 5:19:39 PM8/24/16
to ggplot2
You might try ggplot_build(p4)

--pete

Pete St Marie

unread,
Aug 24, 2016, 5:37:38 PM8/24/16
to ggplot2
The ggplot2 documentation is the place to look.
For example:
library(ggpmisc)
library(ggplot2)

lynx.df <- try_data_frame(lynx, "year")

foo <- ggplot(lynx.df, aes(time, V.lynx)) + geom_line() + 
  stat_peaks(colour = "red") +
  stat_peaks(geom = "text", colour = "red", vjust = -0.5) +
  ylim(-100, 7300)

ggplot_build(foo) # to check on the layers

peak_labels <- layer_data(foo, i = 3)
Reply all
Reply to author
Forward
0 new messages