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?

4
  • is this a related post: stackoverflow.com/questions/7305803/…
    – alittleboy
    Dec 18, 2013 at 7: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. Dec 18, 2013 at 7: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, 2013 at 7: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. Dec 18, 2013 at 8:42

2 Answers 2

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.

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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.