Using ggplot2 in a package

Due to my recent conversion to ggplot2, I am starting to use ggplot() in packages. Running R CMD check on this function

    ggplot(data=data.frame(n=1:n,v=object@vars),
           aes(x=n,y=v))

I got the note

* checking R code for possible problems ... NOTE
colocpc.plot: no visible binding for global variable ‘v’

It turns out this is a known feature of the R checking code. v is indeed undefined. I like a clean run of R CMD check --as-cran for all packages. The link gives a discussion of alternative work-arounds:

Continue reading

pch symbols

I often have used simple code like this to remind myself which number corresponds to which pch character:

par(mar=c(4,1,1,1))
plot(x, y, type="n", ylab="", xlab="pch", axes=FALSE)
box()
axis(1)
abline(v=1:25,lty=3,col="grey")
points(1:25,rep(1,25),pch=1:25)

p2.jpg

I wondered what it would take to do the same in ggplot2. The amount of typing required to remove (most of) the y axis kinda annoys me, but otherwise, it’s quite nice:

ggplot(data.frame(x=x,y=y), aes(x=x,y=y,pch=as.factor(x))) +
  geom_point() +
  xlab("pch") + ylab("") +
  scale_shape_manual(values=1:25) +
  opts(legend.position="none",
       axis.title.y = theme_blank(),
       axis.text.y =  theme_blank() )

p3.jpg

Coloc 1.10

Coloc version 1.10 on CRAN. This version adds the option to calculate a credible interval for eta from its posterior distribution.

It uses a rather crude search to find the highest posterior density region, based on a numerical approximation of the posterior. The search proceeds outwards from the mode in largish steps until the desired level of the interval is exceeded, then inwards in small steps. It could certainly be optimized, but this way was quick to program and runs in a few seconds, so appeared reasonable. The calculation can be turned off by setting bayes.ci=FALSE to speed things up when time really matters in simulations.

Posted in R

Hello world!

I have created a github repo to hold bits and pieces of R code that I want to keep some revision history for. This WordPress site is where I will keep notes when I write them. I’m trying to adopt this new way of working so that I save future time spent trying to understand what old code did. Sometimes the bits and bobs might be packaged up properly.

I hope also to document where I find any useful snippets or interesting use.