summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Kellner <ken@kenkellner.com>2023-11-04 09:23:57 -0400
committerKen Kellner <ken@kenkellner.com>2023-11-04 09:23:57 -0400
commite3737849021461f13e1f063f468802a6642052e8 (patch)
tree204b7af7ef93d87c7af3a482be18bd183624c1ce
parent307add525155353ebfe7993e6915b01f8f0fb252 (diff)
Remove plotrix dependency
-rw-r--r--DESCRIPTION6
-rw-r--r--NAMESPACE4
-rw-r--r--R/draw_circle.R43
-rw-r--r--R/simHDS_AHM1_8-5-1_Simulate_hierarch_distance_sampling.R2
-rw-r--r--R/simHDSg_AHM1_9-2-1_Simulate_hierarch_distance_sampling_groups.R2
-rw-r--r--R/simHDSpoint.R2
-rw-r--r--R/simHDStr.R1
-rw-r--r--R/simPdata_AHM1_8-2-5-1_Simulate_point_transect_data.R2
8 files changed, 52 insertions, 10 deletions
diff --git a/DESCRIPTION b/DESCRIPTION
index 6cb761f..86f9984 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,10 +1,10 @@
Package: AHMbook
Type: Package
Title: Functions and Data for the Book 'Applied Hierarchical Modeling in Ecology' Vols 1 and 2
-Version: 0.2.9
-Date: 2023-08-21
+Version: 0.2.10
+Date: 2023-11-04
Depends: R (>= 2.10)
-Imports: grDevices, graphics, methods, stats, utils, plotrix, raster, sp, fields, coda, unmarked (>= 0.12.2), mvtnorm, spdep
+Imports: grDevices, graphics, methods, stats, utils, raster, sp, fields, coda, unmarked (>= 0.12.2), mvtnorm, spdep
Authors@R: c(
person("Marc", "Kéry", role="aut"),
person("Andy", "Royle", role="aut"),
diff --git a/NAMESPACE b/NAMESPACE
index dfe470c..66273fb 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,7 +1,7 @@
# NAMESPACE for AHMbook package
importFrom("grDevices", "colorRampPalette", "devAskNewPage", "dev.interactive",
- "topo.colors", "adjustcolor", "rgb")
+ "topo.colors", "adjustcolor", "rgb", "dev.cur")
importFrom("graphics", "abline", "barplot", "curve", "hist", "image",
"lines", "matplot", "par", "plot", "points", "polygon", "mtext",
"rect", "segments", "text", "title", "axis", "legend", "box")
@@ -19,7 +19,7 @@ importFrom("unmarked", "unmarkedFrameOccu", "unmarkedFramePCount", "unmarkedFram
importFrom("raster", "raster", "extent", "extent<-", "rasterFromXYZ",
"getValues", "image", "addLayer", "dropLayer", "ncell",
"values", "values<-", "xyFromCell", "aggregate", "subset")
-importFrom("plotrix", "draw.circle")
+# importFrom("plotrix", "draw.circle") # Now in file draw_circle.R
# importFrom("RandomFields", "RFoptions", "RFsimulate", "RMexp")
importFrom("fields", "circulantEmbeddingSetup", "circulantEmbedding")
importFrom("sp", "bubble", "coordinates<-")
diff --git a/R/draw_circle.R b/R/draw_circle.R
new file mode 100644
index 0000000..ce68700
--- /dev/null
+++ b/R/draw_circle.R
@@ -0,0 +1,43 @@
+# Functions from the orphaned (~11/2023) plotrix R package
+# Authors: Jim Lemon, Ben Bolker, Sander Oom, Eduardo Klein, Barry Rowlingson,
+# Hadley Wickham, Anupam Tyagi, Olivier Eterradossi, Gabor Grothendieck, Michael Toews,
+# John Kane, Rolf Turner, Carl Witthoft, Julian Stander, Thomas Petzoldt, Remko Duursma,
+# Elisa Biancotto, Ofir Levy, Christophe Dutang, Peter Solymos, Robby Engelmann,
+# Michael Hecker, Felix Steinbeck, Hans Borchers, Henrik Singmann, Ted Toal,
+# Derek Ogle, Darshan Baral, Ulrike Groemping, Bill Venables, The CRAN Team
+# License GPL-3
+# https://cran.r-project.org/package=plotrix
+# https://github.com/plotrix/plotrix
+draw.circle<-function(x,y,radius,nv=100,border=NULL,col=NA,
+ lty=1,density=NULL,angle=45,lwd = 1) {
+
+ xylim<-par("usr")
+ plotdim<-par("pin")
+ ymult<-getYmult()
+ angle.inc<-2*pi/nv
+ angles<-seq(0,2*pi-angle.inc,by=angle.inc)
+ if(length(col)<length(radius))
+ col<-rep(col,length.out=length(radius))
+ for(circle in 1:length(radius)) {
+ xv<-cos(angles)*radius[circle]+x
+ yv<-sin(angles)*radius[circle]*ymult+y
+ polygon(xv,yv,border=border,col=col[circle],lty=lty,
+ density=density,angle=angle,lwd=lwd)
+ }
+ invisible(list(x=xv,y=yv))
+}
+
+getYmult<-function() {
+ if(dev.cur() == 1) {
+ warning("No graphics device open.")
+ ymult<-1
+ }
+ else {
+ # get the plot aspect ratio
+ xyasp<-par("pin")
+ # get the plot coordinate ratio
+ xycr<-diff(par("usr"))[c(1,3)]
+ ymult<-xyasp[1]/xyasp[2]*xycr[2]/xycr[1]
+ }
+ return(ymult)
+}
diff --git a/R/simHDS_AHM1_8-5-1_Simulate_hierarch_distance_sampling.R b/R/simHDS_AHM1_8-5-1_Simulate_hierarch_distance_sampling.R
index 2a202df..b90264f 100644
--- a/R/simHDS_AHM1_8-5-1_Simulate_hierarch_distance_sampling.R
+++ b/R/simHDS_AHM1_8-5-1_Simulate_hierarch_distance_sampling.R
@@ -123,7 +123,7 @@ if(show.plot) {
"Located individuals in point transects", xlim = c(0, 2*B),
ylim = c(0, 2*B), col = data[,1], asp = 1)
points(B, B, pch = "+", cex = 3, col = "black")
- plotrix::draw.circle(B, B, B)
+ draw.circle(B, B, B)
hist(data[,"d"], col = "lightblue", breaks = 20, main =
"Frequency of distances", xlab = "Distance")
ttt <- table(data[,1])
diff --git a/R/simHDSg_AHM1_9-2-1_Simulate_hierarch_distance_sampling_groups.R b/R/simHDSg_AHM1_9-2-1_Simulate_hierarch_distance_sampling_groups.R
index 2e7a5ca..253f1e3 100644
--- a/R/simHDSg_AHM1_9-2-1_Simulate_hierarch_distance_sampling_groups.R
+++ b/R/simHDSg_AHM1_9-2-1_Simulate_hierarch_distance_sampling_groups.R
@@ -111,7 +111,7 @@ if(show.plot) {
"Located groups in point transects", xlim = c(0, 2*B),
ylim = c(0, 2*B), col = data[,1], asp = 1)
points(B, B, pch = "+", cex = 3)
- plotrix::draw.circle(B, B, B)
+ draw.circle(B, B, B)
hist(data[,"d"], col = "lightblue", breaks = 20, main =
"Frequency of distances to groups", xlab = "Distance")
ttt <- table(data[,1])
diff --git a/R/simHDSpoint.R b/R/simHDSpoint.R
index c7312fd..9deb276 100644
--- a/R/simHDSpoint.R
+++ b/R/simHDSpoint.R
@@ -88,7 +88,7 @@ if(show.plots) {
"Locations of detected individuals", xlim = c(-B, B),
ylim = c(-B, B), col = data[,1], asp = 1)
points(0, 0, pch = "+", cex = 3, col = "black")
- plotrix::draw.circle(0, 0, B)
+ draw.circle(0, 0, B)
tmp <- hist(unlist(Nlist), breaks = 20, xlim=c(0, B), xlab = "Distance",
main = "Frequency of distances\nblue: detected, gray: undetected")
diff --git a/R/simHDStr.R b/R/simHDStr.R
index 5b3c348..62290d1 100644
--- a/R/simHDStr.R
+++ b/R/simHDStr.R
@@ -187,7 +187,6 @@ if(show.plot) {
main = "Located groups in point transects", xlim = c(0, 2*B),
ylim = c(0, 2*B), col = data[,1], asp = 1)
points(B, B, pch = "+", cex = 3)
- # library(plotrix)
draw.circle(B, B, B)
hist(data[,"d"], col = "lightblue", breaks = 20, main =
"Frequency of distances to groups", xlab = "Distance")
diff --git a/R/simPdata_AHM1_8-2-5-1_Simulate_point_transect_data.R b/R/simPdata_AHM1_8-2-5-1_Simulate_point_transect_data.R
index e072f41..26b55e8 100644
--- a/R/simPdata_AHM1_8-2-5-1_Simulate_point_transect_data.R
+++ b/R/simPdata_AHM1_8-2-5-1_Simulate_point_transect_data.R
@@ -45,7 +45,7 @@ if(show.plot) {
points(u1[d <= B], u2[d <= B], pch = 16, col = "black")
points(u1[y==1], u2[y==1], pch = 16, col = "blue")
points(B, B, pch = "+", cex = 3, col = "red")
- plotrix::draw.circle(B, B, B)
+ draw.circle(B, B, B)
}, silent = TRUE)
if(inherits(tryPlot, "try-error"))
tryPlotError(tryPlot)