Plotting cva.glmnet()

40 views Asked by At

I have a plot from a cva.glmnet() object.

The plot's legend is in the way, and I can't figure out how to move it to the right and give it a legend title.

Here's some sample code that gives a similar issue.

set.seed(100)
a <- runif(1000) %>% round()
b <- runif(1000) %>% round()
c <- runif(1000) %>% round()
d <- runif(1000) %>% round()
datatest <- as.data.frame(cbind(a,b,c,d))
cvtest <- cva.glmnet(d ~ a+b+c, data= datatest, family = "binomial")
plot(cvtest)

Here's a picture of the output:

enter image description here

I've tried adding a legend and using ggplot().

1

There are 1 answers

2
jay.sf On

Looks like a bug. We can still set legend coordinates to NULL and customize a legend.

par(mar=c(4, 4, 1, 1)+.1)
glmnetUtils:::plot.cva.glmnet(cvtest, legend.x=NULL, legend.y=NULL)  ## just plot(.) is sufficient
a <- cvtest$alpha
legend('topright', leg=a, lty=1, col=topo.colors(length(a)), ncol=2, cex=.8)

enter image description here

Note, that there's no ggplot2 package involved which is why your attempt didn't work.