Re: Grab data from plot.secr

117 views
Skip to first unread message

Murray Efford

unread,
Jun 4, 2018, 11:00:36 PM6/4/18
to Henrik P, secr
Hi Henrik
For me, plot.secr already returns these values invisibly. Did you overlook that?
Murray

On Mon, Jun 4, 2018 at 10:29 PM, Henrik P <henri...@gmail.com> wrote:
I wish to grab the data created by plot.secr, i.e. x and y values, lcl and ucl, to use for further processing (e.g. plotting in other packages/software)

My use case is a model of sex differences in g0 and sigma,  where I want to plot the lines for each sex in different colors. Currently I use plot.secr like this:  

# create toy data
# add covariate 'sex' to capt
set.seed(123)
covariates(captdata) <- data.frame(sex = sample(c("f", "m"), size = nrow(captdata),
                                                         p = c(0.4, 0.6), replace = TRUE))

# set starting value of spatial scale
sv <- RPSV(captdata, CC = TRUE)

# fit model 
m <- secr.fit(captdata, model = list(g0 ~ sex, sigma ~ sex),
                    CL = TRUE, buffer = 4 * is, trace = FALSE)

# plot males and females 
# plot first level of sex, female, coded as 0
plot(m, newdata = data.frame(sex = 0), limits = TRUE, col = "red", xval = 0:100, ylim = c(0, 0.5))

# plot second level of sex, male, coded as 1
plot(m, newdata = data.frame(sex = 1), limits = TRUE, add = TRUE, col = "green")


However, for consistency with other (non-secr) plots I have created, I wish to use e.g. lattice or ggplot to visualize my secr results. I therefore need to be able to save the data generated by plot.secr.
 
I suppose I would need to add invisible(data.frame(x = xval, y = y, lcl = lcl, ucl = ucl)) to the plot.secr function somewhere (analogous to e.g. boxplot.default, where, in addition to the actual plot, also the values calculated by the function are returned), but so far my attempts have failed.

Does anyone know do to grab the data from plot.secr? Is this a feature which may be considered in secr?

--
You received this message because you are subscribed to the Google Groups "secr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to secrgroup+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Henrik P

unread,
Jun 6, 2018, 9:05:22 AM6/6/18
to secr
Thanks Murray! It turned out it was a stupid mistake on my side (which is why I deleted my original post). It indeed works as intended. I think you can just delete this thread. Sorry for the inconvenience. 

Cheers,

Henrik
To unsubscribe from this group and stop receiving emails from it, send an email to secrgroup+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages