1

I have plotted six models each in a separate plot.

My question is: how can I combine them in one graphical plot using R?

The code I use is:

fitemax <- fitMod(dose, resp, data=biom, model="emax",bnds = c(0.00, 1))
plot(fitemax)

fitlinearlog <- fitMod(dose, resp, data=biom, model="linlog",bnds = c(0.00, 1))
plot(fitlinearlog)

fitlinear <- fitMod(dose, resp, data=biom, model="linear",bnds = c(0.00, 1))
plot(fitlinear)

fitquadratic <- fitMod(dose, resp, data=biom, model="quadratic",bnds = c(0.00, 1))
plot(fitquadratic)

fitexponential <- fitMod(dose, resp, data=biom, model="exponential",bnds = c(0.00,1))
plot(fitexponential)

fitlogistic <- fitMod(dose, resp, data=biom, model="logistic",defBnds(MaxEff, 
logistic = matrix(c(0.0, 0.2, 0.4, 0.8)*MaxEff, 2)))
plot(fitlogistic)

The data cabe be found in R in the DoseFinding Package

John Paul
  • 12,196
  • 6
  • 55
  • 75
SAMA
  • 11
  • 2
  • 1
    What exactly is the desired output? What would this "one plot" look like? The code you've provided is essentially useless because you didn't provide any data so we could actually run it so we have no idea what those plots look like. Please create a truly [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick Sep 05 '14 at 01:12

1 Answers1

2

Use par(mfrow=c(2,3)) to make the following plot be arranged in one 2 * 3 grid.

If you want fine control, keep reading here(layout), here(ggplot+gridExtra)

png(filename="C:\\Users\\datafireball.com\\Documents\\R\\stackoverflow_7144118.png")
par(mfrow=c(3,2))
plot(rnorm(10), rnorm(10))
plot(rnorm(10), rnorm(10))
plot(rnorm(10), rnorm(10))
plot(rnorm(10), rnorm(10))
plot(rnorm(10), rnorm(10))
plot(rnorm(10), rnorm(10))
dev.off()

You can remove the first and last line so you can print it to the standout output.

enter image description here

Update: In your case, looks like par(mfrow) won't work, because I don't think it is actually calling the base plot method, instead, the return object from the fitMod method is actually a type called "trellis", which belongs to the lattice package. If you want to know more about trellis, read here. However, if you just want to know how to get it work, I got it working with the grid.arrange method from gridExtra.

library(DoseFinding)
library(gridExtra)
data(biom)
# here, the bnds argument has been ignored so the default value from defBnds will be applied. 
fitemax <- fitMod(dose, resp, data=biom, model="emax")
p1 <- plot(fitemax)
fitlinearlog <- fitMod(dose, resp, data=biom, model="linlog")
p2 <- plot(fitlinearlog)
fitlinear <- fitMod(dose, resp, data=biom, model="linear")
p3 <- plot(fitlinear)
fitquadratic <- fitMod(dose, resp, data=biom, model="quadratic")
p4 <- plot(fitquadratic)
fitexponential <- fitMod(dose, resp, data=biom, model="exponential")
p5 <- plot(fitexponential)
fitlogistic <- fitMod(dose, resp, data=biom, model="logistic")
p6 <- plot(fitlogistic)
grid.arrange(p1, p2, p3, p4, p5, p6)
# Message: Need bounds in "bnds" for nonlinear models, using default bounds from "defBnds".

enter image description here

Is this the output you want?

B.Mr.W.
  • 18,910
  • 35
  • 114
  • 178
  • this does not really work with my data , the is stored in r under the dose finding package the data is ( biom) I tried every thing but still displayed individually – SAMA Sep 06 '14 at 09:09
  • If this answer doesn't work with your specific dataset, then you should supply a reproducible (!) data example that resembles its most important features. – SimonG Sep 06 '14 at 13:35
  • I used the following command ; fitlogistic <- fitMod(dose, resp, data=biom, model=="logistic",defBnds(MaxEff, logistic = matrix(c(0.0, 0.2, 0.4, 0.8)*MaxEff, 2))) plot(fitlogistic) , but its says this message ; Message: S argument ignored for type == "normal" Error in checkAnalyArgs(dose, resp, data, S, type, addCovars, placAdj, : S needs to be of class matrix > plot(fitlogistic) Error in plot(fitlogistic) : object 'fitlogistic' not found > – SAMA Sep 07 '14 at 01:15
  • @SAMA, clearly, you are trying to pass some limit to the `bnd` argument, how to use the a specific question is already outside the scope of this question and I would recommend you start another thread to let the people who has the expertise give an answer. However, based on what I know. The `bnd` will pick up some default value which actually performs really out of box. As you can see from the plot. – B.Mr.W. Sep 07 '14 at 01:43
  • @B.Mr.W. , I tried the commands as above and I get this Message fitemax <- fitMod(dose, resp, data=biom, model="emax") Message: Need bounds in "bnds" for nonlinear models, using default bounds from "defBnds". – SAMA Sep 10 '14 at 02:28