Reputation: 11
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
Upvotes: 1
Views: 619
Reputation: 19648
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.
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".
Is this the output you want?
Upvotes: 2