Closed caixu0518 closed 9 months ago
I resolved it by using ggplot_build(). Thank you for your nice package.
@caixu0518 Thanks for reporting the solution you found. Anyway, I will see if the internal function used within package 'ggmisc' is robust enough to be exported in a future version of 'ggpmisc'.
many thanks for your reply. Based on your wonderful packages, I can generate all peaks now. However, I found too many false peaks from the results of 'ggpmisc'. I hope you can give me some advice for how to filter the 'false peaks'. Here, I present an example, the example shows there are four peaks (the values are 0.0130513,0.1637344,0.2895015,0.3867929)from the results of your packages, but from my eyes, there are should be only one peak.
@caixu0518 If two consecutive x
values have identical y
values, they are both returned. Could this be what you are seeing?
Not exactly,I found that the output of ‘ggpmisc’ provides so many small peaks. As the example provided above, some extra small peaks are formed because the curve is not smooth enough. I want to know is there any way for me to make the curve smooth and extract the main peak? For example, the employment of 'gaussian curve'?
Best, Xu
Can we correct the curve firstly, then we calculate the peaks using the ‘ggpmisc’ package?
@caixu0518 Hi. Thanks! Some questions and some things to consider.
stat_peaks()
to compute the peaks and you have no use for the plot?span
control the width of the window. With a wide window you get fewer peaks, with span = NULL
you get a single peak. The odd integer number passed to span
determines the with of the window as number of observations. Have you tried this?stat_peaks()
strict=TRUE
and two or more observations share the same maximum value within the window, none of them will be considered peaks. ignore_threshold
to ignore a local peaks below a given height.Except for the support of span=NULL
and ignore_threshold
all the work of finding the peaks in 'ggpmisc' is done by function peaks()
from R package 'splus2R'. The only thing you need to be careful about is that this function takes a vector (of y values) as argument, and these y values must be ordered by their corresponding x values. In other words, in the same order as plotted along x.
To do: Export a function to extract peaks from a data frame consistently with stat_peaks()
and stat_valleys()
.
Possibly also implement some kind of peak fitting and n.min
parameter.
@caixu0518 Function find_peaks()
is now exported in the code at GitHub. Will be in CRAN rather soon as version 0.5.5.
Peak fitting is not yet implemented. New parameters n.min
and n.max
could be used to dynamically adjust the span
, or the ignore_threshold
. Moved to new issue #48 for future implementation.
These days I used your nice package, It looks brilliant. I got a minor question.
I want to save the values of peaks into a new file, but now i can only plot the values in the figure. Is there any way for me to do this?
Best, Xu