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
Hi Bruce & Abby, Here is a start on merging the two plots. Abby - I had to cheat on the legend colors as I could not work out from the help pages how to specify the range of colors. Also I don't know the range of densities. Both should be easy to fix. While I specified xlab and ylab, they don't seem to make it to the plotting functions. More study needed. Bruce - The following code gives general idea of how to automate plotting from a single data set. let me know whether you want automated adjustment of axes, etc. Both - I suspect that the constraints forming the diagonal lines are due to characteristics of the bat larynx. bfs<-read.csv("Procen_sample.csv") # split out what you want to identify the plot species<-unlist(strsplit("Procen_sample.csv","_"))[1] library(bivariate) # define the plot sequence 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) } # open the device png(paste0(species,".png")) # leave space for the color legend par(mar=c(6,4,4,2)) plot_ds (bfs[,c("Fc","Sc")], main=paste(species,"characteristic bat call"), xlab="Frequency (kHz)",ylab="Characteristic slope (octaves/s)", ,k1=1.25, k2=1.25) library(plotrix) xylim<-par("usr") color.legend(xylim[1],xylim[3]-(xylim[4]-xylim[3])/7, xylim[1]+(xylim[2]-xylim[1])/4,xylim[3]-(xylim[4]-xylim[3])/10, legend=seq(0,10,length.out=5), rect.col=color.scale(0:4,extremes=c("#7be6bd","#bdb3df")),align="rb") text(xylim[1]+(xylim[2]-xylim[1])/8, xylim[3]-(xylim[4]-xylim[3])/5, "Density",xpd=TRUE) dev.off() Jim On Wed, Jun 3, 2020 at 6:22 AM Neotropical bat risk assessments <neotropical.bats at gmail.com> wrote:> > 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 >-------------- next part -------------- A non-text attachment was scrubbed... Name: Procen.png Type: image/png Size: 30320 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20200603/112c94e3/attachment.png>
Tnx Jim, Yes if there is a way to first extract the ranges of each data files Fc range and Sc ranges and then link to the plot that would be stellar. I will look at this code and see how it is working so far. Thanks a million. Bruce> Hi Bruce & Abby, > Here is a start on merging the two plots. > Abby - I had to cheat on the legend colors as I could not work out > from the help pages how to specify the range of colors. Also I don't > know the range of densities. Both should be easy to fix. While I > specified xlab and ylab, they don't seem to make it to the plotting > functions. More study needed. > Bruce - The following code gives general idea of how to automate > plotting from a single data set. let me know whether you want > automated adjustment of axes, etc. > Both - I suspect that the constraints forming the diagonal lines are > due to characteristics of the bat larynx. > > bfs<-read.csv("Procen_sample.csv") > # split out what you want to identify the plot > species<-unlist(strsplit("Procen_sample.csv","_"))[1] > library(bivariate) > # define the plot sequence > 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) > } > # open the device > png(paste0(species,".png")) > # leave space for the color legend > par(mar=c(6,4,4,2)) > plot_ds (bfs[,c("Fc","Sc")], > main=paste(species,"characteristic bat call"), > xlab="Frequency (kHz)",ylab="Characteristic slope (octaves/s)", > ,k1=1.25, k2=1.25) > library(plotrix) > xylim<-par("usr") > color.legend(xylim[1],xylim[3]-(xylim[4]-xylim[3])/7, > xylim[1]+(xylim[2]-xylim[1])/4,xylim[3]-(xylim[4]-xylim[3])/10, > legend=seq(0,10,length.out=5), > rect.col=color.scale(0:4,extremes=c("#7be6bd","#bdb3df")),align="rb") > text(xylim[1]+(xylim[2]-xylim[1])/8, > xylim[3]-(xylim[4]-xylim[3])/5, > "Density",xpd=TRUE) > dev.off() > > Jim > > On Wed, Jun 3, 2020 at 6:22 AM Neotropical bat risk assessments > <neotropical.bats at gmail.com> wrote: >> 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 >>-- 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
> 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.I need to re-iterate, that the diagonal lines, may be important. Also, I'm not sure I see the point in adding density values. Unless people have a good knowledge of probability theory and calculus, I doubt that specific density values will be useful. i.e. If I said the density was 0.0035, what does that tell you...? If you really want to add a legend, it's possible. But this creates at least two problems: (1) In the base graphics system, the resulting plots can't be nested. (2) It's difficult to interpret specific color-encoded values. In my opinion, a better idea, is to label the contour lines. In my packages, this is possible by using contour.labels=TRUE, however, the defaults are ugly. (Something else for my todo list). Here's a slightly more complex example, with prettier contour labels: library (barsurf) library (KernSmooth) set.bs.theme ("heat") plot_ds <- function (dataset, main="", xlim, ylim, ..., ncontours=3, labcex=0.8, ndec=3, k1=1, k2=1, n=30) { names <- names (dataset) x <- dataset [,1] y <- dataset [,2] bw.x <- k1 * bw.nrd (x) bw.y <- k2 * bw.nrd (y) if (missing (xlim) ) xlim <- range (x) + c(-1, 1) * bw.x if (missing (ylim) ) ylim <- range (y) + c(-1, 1) * bw.y ks <- bkde2D (dataset, c (bw.x, bw.y), c (n, n), list (xlim, ylim), FALSE) fb <- seq (min (ks$fhat), max (ks$fhat), length.out = ncontours + 2) fb <- fb [2:(ncontours + 1)] fb <- round (fb, ndec) plot_cfield (ks$x1, ks$x2, ks$fhat, contours=FALSE, main=main, xlab = names [1], ylab = names [2], xyrel="m") points (x, y, pch=16, col="#00000040") contour (ks$x1, ks$x2, ks$fhat, levels=fb, labcex=labcex, add=TRUE) } plot_ds (bat_call, "plot 2", c (25, 28), c (-15, 10), k1=1.25, k2=1.25) If you still want a legend, have a look at: graphics::filled.contour And then modify the second half of my code, starting after ks <- ...
Hi Abby, Tried this new version but did not execute... Clearly I am missing a step. Bruce > library (barsurf) > library (KernSmooth) > set.bs.theme ("heat") > > plot_ds <- function (dataset, main="", xlim, ylim, ..., + ncontours=3, labcex=0.8, ndec=3, + k1=1, k2=1, n=30) + {?? names <- names (dataset) + x <- dataset [,1] + y <- dataset [,2] + bw.x <- k1 * bw.nrd (x) + bw.y <- k2 * bw.nrd (y) + if (missing (xlim) ) + xlim <- range (x) + c(-1, 1) * bw.x + if (missing (ylim) ) + ylim <- range (y) + c(-1, 1) * bw.y + + ks <- bkde2D (dataset, c (bw.x, bw.y), + c (n, n), list (xlim, ylim), FALSE) + + fb <- seq (min (ks$fhat), max (ks$fhat), + length.out = ncontours + 2) + fb <- fb [2:(ncontours + 1)] + fb <- round (fb, ndec) + + plot_cfield (ks$x1, ks$x2, ks$fhat, + contours=FALSE, + main=main, xlab = names [1], ylab = names [2], + xyrel="m") + points (x, y, pch=16, col="#00000040") + contour (ks$x1, ks$x2, ks$fhat, levels=fb, labcex=labcex, add=TRUE) + } > > plot_ds (bat_call, "plot 2", c (25, 28), c (-15, 10), k1=1.25, k2=1.25) *Error in plot_ds(bat_call, "plot 2", c(25, 28), c(-15, 10), k1 = 1.25,? : ** **? object 'bat_call' not found* [[alternative HTML version deleted]]