Very nice. I forgot that you didn't have the complete data set. png("as_bat_call.png") plot_ds (bfs[,c("Fc","Sc")], "plot 1", xlim = c (25, 30), ylim = c (-15, 10), k1=1.25, k2=1.25) dev.off() Jim On Tue, Jun 2, 2020 at 6:24 PM Abby Spurdle <spurdle.a at gmail.com> wrote:> > I'm putting this back on the list. > > > So how would I set up the code to do this with the data type I have? > > > I will need to replicate the same task > 200 times with other data sets. > > What I need to do is plot *Fc *against *Sc* with the third dimension being the *density* of the data points. > > Using Jim's bat_call data: > > library (bivariate) > > plot_ds <- function (dataset, main="", xlim, ylim, ..., k1=1, k2=1) > { names <- names (dataset) > fh <- kbvpdf (dataset [,1], dataset [,2], k1 * bw.nrd (dataset > [,1]), k2 * bw.nrd (dataset [,2]) ) > plot (fh, main=main, xlab = names [1], ylab = names [2], > xlim=xlim, ylim=ylim, > ncontours=2) > } > > plot_ds (bat_call, "plot 1", k1=1.25, k2=1.25) > > Note that I've used stats::bw.nrd. > The k1 and k2 values, simply scale the default bandwidth. > (In this case, I've increased the smoothness). > > If you want to do it 200+ times: > (1) Create another function, to iterate over each data set. > (2) If you want to save the plots, you will need to add in a call to > pdf/png/etc and close the device, in each iteration. > (3) It may be desirable to have constant xlim/ylim values, ideally > based on the ranges of the combined data: > > plot_ds (bat_call, "plot 1", xlim = c (25, 30), ylim = c (-15, 10), > k1=1.25, k2=1.25) > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-------------- next part -------------- A non-text attachment was scrubbed... Name: as_bat_call.png Type: image/png Size: 26580 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20200602/17c1cb64/attachment.png>
Hi all, Many thanks for the efforts and suggestions. This is getting closer to what is needed.? No legend showing the density values yet. I was able to replicate a similar plot with the original data set. However when I tried this with a different data set that has other Fc & Sc values? the plot does not work... just a blank PNG Code from console below: ?>bfs<-Eptfur > dim(bfs) [1] 5638?? 17 > names(bfs) ?[1] "Filename" "st"?????? "Dur"????? "TBC"????? "Fmax" "Fmin"???? "Fmean" ?[8] "Tk"?????? "Fk"?????? "Qk"?????? "Tc"?????? "Fc" "Dc"?????? "S1" [15] "Sc"?????? "Qual"???? "Pmc" > library(plotrix) > # set the matrix limits a bit beyond the data ranges > fcsc_mat<-makeDensityMatrix(bfs$Fc,bfs$Sc,nx=25,ny=25, + zfun="sum",xlim=c(24,29),ylim=c(-20,10)) Range of density (>0) - Inf -Inf Warning messages: *1: In min(x) : no non-missing arguments to min; returning Inf** **2: In max(x) : no non-missing arguments to max; returning -Inf* > png("bat_call_plot.png") > par(mar=c(6,4,4,2)) > color2D.matplot(fcsc_mat, + main="Freqency by slope of bat calls", + extremes=c("yellow","red"),xlab="Frequency (kHz)", + ylab="Characteristic slope (octaves/s)", + border=NA,axes=FALSE) Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf 3: In min(x) : no non-missing arguments to min; returning Inf 4: In max(x) : no non-missing arguments to max; returning -Inf > axis(1,at=seq(5,95,10),round(seq(24.5,28.5,length.out=10),1)) > axis(2,at=seq(5,95,10),round(seq(-20,10,length.out=10),1)) > color.legend(0,-14,25,-10,legend=seq(0,10,length.out=5), + rect.col=color.scale(0:4,extremes=c("yellow","red")),align="rb") > text(12.5,-20,"Density (cell count)",xpd=TRUE) > dev.off() null device ????????? 1 I will not need to add a function it iterate as I will not be running? this as an iterative task at one time... I just need the code to be able to use different data sets that have the same fields. The Sc values over the 200+ data sets will range from potentially large negative numbers to positive numbers depending on the slope of the calls, i.e. increasing frequencies or decreasing frequencies. An example of these two parameters for a single species with descriptive stats. N is valid number of call pulses, then 10%-90% bins of where the call pulses fall into. Parameters N Min Max Mean St.Dev 10% 25% 75% 90% Fc 32802 43.01 50.00 46.86 1.31 45.07 45.98 47.76 48.63 Sc 32802 -309.78 13.76 -6.60 10.98 -10.31 -7.50 -3.91 -2.81 I am very appreciative and thank you both for guiding the efforts. Bruce> Very nice. I forgot that you didn't have the complete data set. > > png("as_bat_call.png") > plot_ds (bfs[,c("Fc","Sc")], "plot 1", xlim = c (25, 30), ylim = c (-15, 10), > k1=1.25, k2=1.25) > dev.off() > > Jim > > On Tue, Jun 2, 2020 at 6:24 PM Abby Spurdle <spurdle.a at gmail.com> wrote: >> I'm putting this back on the list. >> >>> So how would I set up the code to do this with the data type I have? >>> I will need to replicate the same task > 200 times with other data sets. >>> What I need to do is plot *Fc *against *Sc* with the third dimension being the *density* of the data points. >> Using Jim's bat_call data: >> >> library (bivariate) >> >> plot_ds <- function (dataset, main="", xlim, ylim, ..., k1=1, k2=1) >> { names <- names (dataset) >> fh <- kbvpdf (dataset [,1], dataset [,2], k1 * bw.nrd (dataset >> [,1]), k2 * bw.nrd (dataset [,2]) ) >> plot (fh, main=main, xlab = names [1], ylab = names [2], >> xlim=xlim, ylim=ylim, >> ncontours=2) >> } >> >> plot_ds (bat_call, "plot 1", k1=1.25, k2=1.25) >> >> Note that I've used stats::bw.nrd. >> The k1 and k2 values, simply scale the default bandwidth. >> (In this case, I've increased the smoothness). >> >> If you want to do it 200+ times: >> (1) Create another function, to iterate over each data set. >> (2) If you want to save the plots, you will need to add in a call to >> pdf/png/etc and close the device, in each iteration. >> (3) It may be desirable to have constant xlim/ylim values, ideally >> based on the ranges of the combined data: >> >> plot_ds (bat_call, "plot 1", xlim = c (25, 30), ylim = c (-15, 10), >> k1=1.25, k2=1.25) >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code.-- Bruce W. Miller, PhD. Neotropical bat risk assessments Conservation Fellow - Wildlife Conservation Society If we lose the bats, we may lose much of the tropical vegetation and the lungs of the planet Using acoustic sampling to identify and map species distributions and pioneering acoustic tools for ecology and conservation of bats for >25 years. Key projects include providing free interactive identification keys and call fact sheets for the vocal signatures of New World Bats [[alternative HTML version deleted]]
Hi all, I spent some time this morning fiddling with the parameters in the plot code provided by Jim and Abby and? by changing some important ones. Jim did note *# set the matrix limits a bit beyond the data ranges* fcsc_mat<-makeDensityMatrix(bfs$Fc,bfs$Sc,nx=100,ny=100, ?zfun="sum",xlim=c(*30,45*),ylim=c(*-55,110*)) and axis(1,at=seq(5,95,10),round(seq(*30.0,50.0*,length.out=10),1)) axis(2,at=seq(5,95,10),round(seq(*-55,110*,length.out=10),1)) So editing the lines above to match what the data includes the plots for various species are working! I now need to figure out how to add a legend for the density values in the bivariate package plots. I am assuming there can be a line or so of code that can extract the min-max values from the actual data files that will update the xlim, ylim and axis data?? I think this should be a simple first step after reading in each new data set. I can not thank Jim and Abby enough.? Super helpful Cheers, Bruce -- Bruce W. Miller, PhD. Neotropical bat risk assessments Conservation Fellow - Wildlife Conservation Society If we lose the bats, we may lose much of the tropical vegetation and the lungs of the planet Using acoustic sampling to identify and map species distributions and pioneering acoustic tools for ecology and conservation of bats for >25 years. Key projects include providing free interactive identification keys and call fact sheets for the vocal signatures of New World Bats [[alternative HTML version deleted]]
> Very niceJim, thank you. However, the (deterministic, or near-deterministic) diagonal lines in the plot, make me question the suitability of this approach. In my plot, the contour lines could be removed, and brighter colors could be used. But perhaps, a better approach would be to model those lines... And it's not clear from the plot, if all the observations fall on a diagonal line... P.S. I'm not sure why there's a white line on the plot. Most of my testing was with PDF output, I will need to do some more testing with PNG output.
Hi Abby, The contour lines are actually useful to see groupings. However w/o a legend for density it is not possible to see what is presented.>> Very nice > Jim, thank you. > However, the (deterministic, or near-deterministic) diagonal lines in > the plot, make me question the suitability of this approach. > In my plot, the contour lines could be removed, and brighter colors > could be used. > > But perhaps, a better approach would be to model those lines... > And it's not clear from the plot, if all the observations fall on a > diagonal line... > > > P.S. > I'm not sure why there's a white line on the plot. > Most of my testing was with PDF output, I will need to do some more > testing with PNG output.-- Bruce W. Miller, PhD. Neotropical bat risk assessments Conservation Fellow - Wildlife Conservation Society If we lose the bats, we may lose much of the tropical vegetation and the lungs of the planet Using acoustic sampling to identify and map species distributions and pioneering acoustic tools for ecology and conservation of bats for >25 years. Key projects include providing free interactive identification keys and call fact sheets for the vocal signatures of New World Bats
On 6/2/20 11:44 AM, Abby Spurdle wrote:>> Very nice > Jim, thank you. > However, the (deterministic, or near-deterministic) diagonal lines in > the plot, make me question the suitability of this approach. > In my plot, the contour lines could be removed, and brighter colors > could be used. > > But perhaps, a better approach would be to model those lines... > And it's not clear from the plot, if all the observations fall on a > diagonal line... > > > P.S. > I'm not sure why there's a white line on the plot.I think if you search the archives of Rhelp you will find many such whinges and that extraneous white lines in PDFs are the fault of the PDF viewing program rather than of R. -- David.> Most of my testing was with PDF output, I will need to do some more > testing with PNG output. > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.