ropenair

create scatter plot matrix with openair and hexbin


I've worked with the openair and hexbin packages to create two scatter plots with the help of the scatter plot function commands:

scatterPlot(mydata, x ="Observed" , y = "Model1",xlab=10, ylab=10,method = "hexbin",mod.line=T,auto.text=F, col = "jet", xbin = 30)

scatterPlot(mydata, x ="Observed" , y = "Model2",xlab=10, ylab=10,method = "hexbin",mod.line=T,auto.text=F, col = "jet", xbin = 30)

I've got the scatter plots, but if I want to put them into one plot and with one color counts to get something similar to this:How should i proceed?

please refer to this link to view the image : https://ibb.co/rF148kp


Solution

  • You could reorganize your data frame so that it has three columns - "Observed", "Modeled", and "Model Type". Example -

    structure(list(observed = c(2L, 2L, 4L, 4L, 6L, 6L, 8L, 8L, 10L, 
    10L, 12L, 12L, 14L, 14L, 16L, 16L, 18L, 18L, 20L, 20L), modelled = c(1L, 
    5L, 7L, 2L, 5L, 9L, 13L, 15L, 16L, 14L, 18L, 17L, 10L, 21L, 26L, 
    24L, 22L, 28L, 27L, 30L), model_type = structure(c(1L, 2L, 1L, 
    2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
    2L), .Label = c("Model 1", "Model 2"), class = "factor")), class = "data.frame", 
    row.names = c(NA, 
    -20L))
    

    This way, you can then use the following code -

    scatterPlot(mydata, x = "observed", y = "modelled", type = c("model_type"),
            method = "hexbin",mod.line=T,auto.text=F, col = "jet", xbin = 5,
            linear = TRUE, layout = c(2, 1))
    

    To create a plot containing the two scatter plots. Note, the above code sets xbin to 5 purely for the reason that I have used a small data set for testing purposes. Also, excuse the spelling error in the y-axis and code ("modelled" should be "modeled")!

    Scatter plots on one plot