

Hi all,
While exploring packages for 3D plots that several folks suggested (Tnx
all!)
It seems what I really need is a contour plot. This is not working int
he Deducer GUI.
This will be an aid to separating bats by their vocal signatures.
What I need to do is plot *Fc *against *Sc* with the third dimension
being the *density* of the data points in the FcSc plot.
Data format is like this abbreviated sample. Fc is a frequency in kHz
and Sc is the characteristic slope (octaves per second) of each call pulse.
Any suggestions, guidance greatly appreciated.
Bruce
Fc Sc
26.58 5.95
27.03 8.2
27.16 2.07
26.19 7.68
26.62 3.99
26.85 6.08
26.94 0
26.1 5.74
26.62 5.96
26.85 4.05
26.98 4.09
26.02 5.69
26.53 7.89
26.62 2
26.8 4.04
28.73 7
25.72 2.97
26.14 5.76
26.32 3.89
26.4 0
26.32 5.88
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Hi Neo,
It's a bit of a guess, but try this:
bat_call<read.table(text="Fc Sc
26.58 5.95
27.03 8.2
27.16 2.07
26.19 7.68
26.62 3.99
26.85 6.08
26.94 0
26.1 5.74
26.62 5.96
26.85 4.05
26.98 4.09
26.02 5.69
26.53 7.89
26.62 2
26.8 4.04
28.73 7
25.72 2.97
26.14 5.76
26.32 3.89
26.4 0
26.32 5.88",
header=TRUE)
library(plotrix)
color2D.matplot(makeDensityMatrix(bat_call$Fc,bat_call$Sc,nx=5,ny=5,
zfun="sum",xlim=range(bat_call$Fc),ylim=range(bat_call$Sc)),
main="Map of bat calls",extremes=c("blue","red"),xlab="Frequency",
ylab="Characteristic slope",axes=FALSE)
axis(1,at=seq(0.5,4.5,1),seq(26.3,28.3,0.5))
axis(2,at=seq(0.5,4.5,1),seq(4,11.2,3.5))
color.legend(0.5,0.65,1,0.45,legend=seq(0,4,length.out=5),
rect.col=color.scale(0:4,extremes=c("blue","red")),align="rb")
text(0.25,0.89,"Density",xpd=TRUE)
Jim
On Mon, Jun 1, 2020 at 3:16 AM Neotropical bat risk assessments
< [hidden email]> wrote:
>
> Hi all,
>
> While exploring packages for 3D plots that several folks suggested (Tnx
> all!)
> It seems what I really need is a contour plot. This is not working int
> he Deducer GUI.
>
> This will be an aid to separating bats by their vocal signatures.
> What I need to do is plot *Fc *against *Sc* with the third dimension
> being the *density* of the data points in the FcSc plot.
>
> Data format is like this abbreviated sample. Fc is a frequency in kHz
> and Sc is the characteristic slope (octaves per second) of each call pulse.
>
> Any suggestions, guidance greatly appreciated.
> Bruce
>
> Fc Sc
> 26.58 5.95
> 27.03 8.2
> 27.16 2.07
> 26.19 7.68
> 26.62 3.99
> 26.85 6.08
> 26.94 0
> 26.1 5.74
> 26.62 5.96
> 26.85 4.05
> 26.98 4.09
> 26.02 5.69
> 26.53 7.89
> 26.62 2
> 26.8 4.04
> 28.73 7
> 25.72 2.97
> 26.14 5.76
> 26.32 3.89
> 26.4 0
> 26.32 5.88
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Hi Bruce,
With a much larger data set, you would see a smoother plot like your
sample. I plotted frequency as the abcissa and slope as the ordinate. It
looks as though your sample has it the other way round and the plot limits
are extended beyond the range of the data. However, makeDensityMatrix and
color2D.matplot could produce a plot like it.
Jim
On Mon, Jun 1, 2020 at 11:13 AM Neotropical bat risk assessments <
[hidden email]> wrote:
> Tnx Jim
>
> Great help.
> I need to read about package plotrix .
> Hoping to achieve something like this sample on right.
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Hi,
I'm probably biased.
But my package, bivariate, contains a wrapper for KernSmooth::bkde2D,
which can produce both 3D surface plots and (pretty) contour plots of
bivariate kernel density estimates, conveniently.
https://cran.rproject.org/web/packages/bivariate/vignettes/bivariate.pdf(pages 18 to 19)
On Mon, Jun 1, 2020 at 5:16 AM Neotropical bat risk assessments
< [hidden email]> wrote:
>
> Hi all,
>
> While exploring packages for 3D plots that several folks suggested (Tnx
> all!)
> It seems what I really need is a contour plot. This is not working int
> he Deducer GUI.
>
> This will be an aid to separating bats by their vocal signatures.
> What I need to do is plot *Fc *against *Sc* with the third dimension
> being the *density* of the data points in the FcSc plot.
>
> Data format is like this abbreviated sample. Fc is a frequency in kHz
> and Sc is the characteristic slope (octaves per second) of each call pulse.
>
> Any suggestions, guidance greatly appreciated.
> Bruce
>
> Fc Sc
> 26.58 5.95
> 27.03 8.2
> 27.16 2.07
> 26.19 7.68
> 26.62 3.99
> 26.85 6.08
> 26.94 0
> 26.1 5.74
> 26.62 5.96
> 26.85 4.05
> 26.98 4.09
> 26.02 5.69
> 26.53 7.89
> 26.62 2
> 26.8 4.04
> 28.73 7
> 25.72 2.97
> 26.14 5.76
> 26.32 3.89
> 26.4 0
> 26.32 5.88
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Good morning Bruce & Abby,
The fruit bats of Sydney have retreated to their camps so I can
finally answer your last two queries. Attached is a plot of your data
set on a 100 x 100 grid. This is how I did it:
bfs<read.csv("Procen_sample.csv")
dim(bfs)
names(bfs)
library(plotrix)
# 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(24,29),ylim=c(20,10))
png("bat_call.png")
par(mar=c(6,4,4,2))
color2D.matplot(fcsc_mat,
main="Freqency by chirp slope of bat calls",
extremes=c("yellow","red"),xlab="Frequency (kHz)",
ylab="Characteristic slope (octaves/s)",
border=NA,axes=FALSE)
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()
Abby's bivariate package looks like it will do some things that
color2D.matplot won't. However, I haven't had time to install it and
try it out, so I don't know whether it will be as easy to plug
different calls onto the same grid. Also, there appears to be
constraints on the frequency and slope in the calls and I don't know
enough about them to say why. Further tweaking may lead to better
solutions.
Jim
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


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)
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


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 < [hidden email]> 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)
>
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


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 nonmissing arguments to min; returning Inf**
**2: In max(x) : no nonmissing 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 nonmissing arguments to min; returning Inf
2: In max(x) : no nonmissing arguments to max; returning Inf
3: In min(x) : no nonmissing arguments to min; returning Inf
4: In max(x) : no nonmissing 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 < [hidden email]> 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)
>>
>> ______________________________________________
>> [hidden email] mailing list  To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/rhelp>> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html>> and provide commented, minimal, selfcontained, 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]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


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
minmax 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]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


> Very nice
Jim, thank you.
However, the (deterministic, or neardeterministic) 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.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


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 neardeterministic) 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
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


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
< [hidden email]> 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 neardeterministic) 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
>
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On 6/2/20 11:44 AM, Abby Spurdle wrote:
>> Very nice
> Jim, thank you.
> However, the (deterministic, or neardeterministic) 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.
>
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


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
> < [hidden email]> 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 neardeterministic) 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
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


> that extraneous white lines in PDFs are the fault of the PDF
> viewing program rather than of R.
Except it's a PNG file.
I've tried to minimize artifacts viewing PDF files.
But assumed (falsely?) that PNGs and other raster formats, would be fine.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


> 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 reiterate, 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 colorencoded 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 < ...
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


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]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


(excerpts only)
> Tried this new version but did not execute...
> Error in plot_ds(bat_call, "plot 2", c(25, 28), c(15, 10), k1 = 1.25, :
> object 'bat_call' not found
I've used the bat_call object, from Jim's earlier post.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

