2

(Very newbie in R) I have a set of coordinates that I want to visualize using hexbin.

bin <- with(mydata,hexbin(x=add, y=rem, xbins=50))
plot(bin)

When I use this, it creates a hexbin plot with count specifying which colours were assigned to which bins. I want to change the way bins are created so that it is in intervals from 0-10, 10-100, 100-1000 etc rather than equal sized bins. I played around with trans and inv options in plot with log10 transform, but this does not seem to be doing what I want it to do. How do I accomplish this?

Rahul Gopinath
  • 808
  • 10
  • 24
  • is this a related post: http://stackoverflow.com/questions/7305803/plot-probability-heatmap-hexbin-with-different-sized-bins – alittleboy Dec 18 '13 at 07:31
  • @alittleboy It appears that only the last post in that link actually splits the bins, and I could not understand what the ggplot does. I am very new at R and not quite familiar with ggplot (can I do this with plot?). I would appreciate any explanations. – Rahul Gopinath Dec 18 '13 at 07:44
  • I am not sure if in base R graphics we can change the size of bins to be unequal... `ggplot2` is a nice and useful package that is more powerful and elegant. I suggest taking a look at it (most likely only in `ggplot2` will the question be solved) – alittleboy Dec 18 '13 at 07:59
  • I would be happy with ggplot2 also, hopefully with a sample application of how to split the bins using a transform. I find the linked question hard to understand. – Rahul Gopinath Dec 18 '13 at 08:42

2 Answers2

0

You can use this code:

bin <- with(mydata,hexbin(x=add, y=rem, xbins=50))
cr <- colorRampPalette(c('gray','blue'))
plot(bin,colramp=cr,border=gray(.75))
Kamil S Jaron
  • 494
  • 10
  • 23
0

hexbin generates S4 object, hence you can log transform the data once you generate the hexplot object.

library(hexbin)

# generate some sample data
add <- rnorm(mean=1.5, 50000)^2
rem <- rnorm(mean=1.6, 50000)
mydata <- data.frame(add,rem)

# generate non-tranformed plot with undesired binning
bin <- hexbin(mydata, xbins=50)
plot(bin) 

enter image description here

# transform data to create log-bins
bin@count <- ceiling(log10(bin@count)) + 1 
plot(bin)

enter image description here

However, I did not manage to make nice legend with it. There is a room for improvement.

Kamil S Jaron
  • 494
  • 10
  • 23