1

About the command 'scatterPlot' from package 'openair' of R, I used the following command:

data(mydata)

scatterPlot(mydata, x = "nox", y = "no2", method = "hexbin",
            colorcut = seq(0, 1, length = 7), cols =  "default", trans=log, inv=exp)

and I got this graphic:

Please Click Here To See The Graphic

I need to know if it is possible to have two Scatterplots on the same graph, one with the method "hexbin" and other with the method "scatter"?

Or, more specifically, it is possible to plot points of another variable over a scatterplot hexbin? I tried to do this for a while, but I did not get hit.

I appreciate any help.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Dani Depi
  • 313
  • 3
  • 16
  • Perhaps you can use `ggplot2`. You could use both `geom_hex` and `geom_point`. For example, using the `diamonds` data set, you could do something like the following `d <- ggplot(diamonds, aes(carat, price))` and `d + geom_hex() + geom_point(aes(carat, price), size = .15, colour = 'magenta', alpha=.15)` – steveb Jan 20 '16 at 20:58
  • I appreciate your answer, `@steveb`. But you can tell me if there is, somehow, some way to make this using `scatterPlot` (by `openair`), or even using `hexbinplot` (by `hexbin`)? – Dani Depi Jan 21 '16 at 00:42
  • I don't really know. I had a quick look at the `openair` manual but didn't see anything that would help. If nobody answers your question on SO, you could contact them at http://www.openair-project.org/Contact.aspx – steveb Jan 21 '16 at 01:35
  • I have already send a email to professor Carslaw, but I asked here too because we never know who can knows too :) Thank you for your attention, @steveb ! – Dani Depi Jan 21 '16 at 02:54
  • @steveb , I'm here to say that professor Carslaw answered my email with the following solution that worked for me: `library(latticeExtra); plt <- scatterPlot(mydata, method = "hexbin", col = "jet"); b <- scatterPlot(head(mydata, 200), col = "black", pch = 16, cex = 0.5); plt$plot + as.layer(b$plot)` – Dani Depi Jan 21 '16 at 22:03
  • That is great to hear. You should put it in this post at the answer. Also, thanks for sharing as well. – steveb Jan 21 '16 at 23:28
  • I just did it @steveb, thanks for your suggestion! – Dani Depi Jan 25 '16 at 23:17

1 Answers1

3

I'm here to say that professor Carslaw (the author of the 'openair' package, which have the 'scatterPlot' command) answered my email with the following solution that worked for me:

library(latticeExtra)
plt <- scatterPlot(mydata, method = "hexbin", col = "jet")
b <- scatterPlot(head(mydata, 200), col = "black", pch = 16, cex = 0.5)
plt$plot + as.layer(b$plot)
Dani Depi
  • 313
  • 3
  • 16