1

I am trying to plot a boxplot and density plot adjacent to each other using the par(mfrow=c(1,2)) argument and it does not work for:

With the following code:

par(mfrow=c(1,2))  
boxplot(x)  
densityplot(x)  

The box plot appears in the left half of the plot device, but densityplot() opens in a new device.

With the order reversed:

par(mfrow=c(1,2))  
densityplot(x)  
boxplot(x)  

The box plot is overlayed on the former.

Here's the dput() of my data if needed:

> dput(x)  
c(79, 56, 69, 61, 53, 73, 72, 86, 75, 68, 74.2, 80, 65.6, 60, 54)  

Does densityplot() not work with the par() argument? Is there a work-around?

avg
  • 793
  • 2
  • 12
  • 24
  • 2
    perhaps some difficulty is using a grid object (densityplot from lattice) with a base R function. Use the base function plot(density(x)) for the density plot or a lattice / ggplot function for the boxplot and then grid.arrange (from gridExtra) – user20650 Aug 05 '13 at 11:54
  • 1
    The gridBase package supports mixing base and lattice graphics. – IRTFM Aug 05 '13 at 17:10
  • why didnt either of you post your comment's as answers (so i can accept)? having searched for 'gridBase', i found a similar question here [link](http://stackoverflow.com/questions/13021863/plots-generated-by-plot-and-ggplot-side-by-side?lq=1), on which @DWin has posted an answer.. – avg Aug 06 '13 at 12:12

0 Answers0