2

I need to customize axis tick marks and tick labels of hexbin plot:

Hexbinning data which best are transformed prior to binning:

library(hexbin)
set.seed(25)
df<-data.frame(x=(rnorm(10000, mean=10, sd=1))^2,y=(rnorm(10000, mean=10, sd=1))^2)
hbo <- hexbin(sqrt(df))

The according plot would then be

plot(hbo,legend=FALSE,xlab="sqrt(x)",ylab="sqrt(y)",main="Transformed data")

I want to backtransform axis tick labels, so that annoying ... ,xlab="sqrt(x)",ylab="sqrt(y)", ... could then be "x" and "y" again.

For base grafics derived plots, one might suppress the axis (x-axis only here) by

plot(hbo,legend=FALSE,main="Quasi-backtranformed data",xaxt="n")

and then issue

axis(side=1,at=seq(6,14,2),labels=seq(6,14,2)^2) 

to recreate the respective axis with backtransformed labels.

But this does NOT work. It does nothing. The hexbin plot method does indeed not honor most par arguments from generic plotting as assumed by @BondedDust. Then, hexbin docs say it uses the grid-package for plotting. Having not worked with grid, I didn't do that good so far and I feel like a total doof.

library(grid)
grid.xaxis(at = seq(6,14,2), vp = viewport(w = .5, h = 0.01), name = "gxa")

again is unresponsive (please don't yell at me).

Above that, axis labels of plot(hexbin-objects) usually overlap with ticklabels, so I would be grateful for a non-Illustrator based method to create fancy hexbin-plots.

Advice on hexbin::tick_mark_and_tick_label_manipulation is greatly appreciated.

Community
  • 1
  • 1
Janhoo
  • 597
  • 5
  • 21
  • 2
    you might be better off with `geom_hexbin()` from the `ggplot2` package ... – Ben Bolker Nov 30 '14 at 13:19
  • thanks @BenBolker. I need to further analyse the bin-counts (http://stackoverflow.com/questions/27155373/hexbin-how-to-trace-bin-contents), so I need something like the hexbin-object. Without looking at ggplot2, it may suck to reproduce hexbin::hexbin with ggplot2. But I'll look into that. – Janhoo Nov 30 '14 at 13:51
  • 1
    @Jan, Please note that you may extract the binned data from a `ggplot` object using `ggplot_build`. Something like `p <- ggplot(df, aes(x, y)) + geom_hex()`; `ggplot_build(p)$data[[1]]` – Henrik Nov 30 '14 at 19:35

0 Answers0