1

So I've been trying to get two Dotplots (Hmisc package) to turn up in the same graph but R draws them sequentially instead.

Anybody know how to draw two Dotplots in the same graph, specifically using the Hmisc package?

I've tried somethings like

par(mfrow = c(1, 2))
Dotplot(latitude~mortality, data=USmelanoma)
Dotplot(longitude~mortality, data=USmelanoma)

But it draws them in two seperate graphs, one after the other instead of in one graph, as I had expect par(mfrow = c(1,2)) to do

Manic Lama
  • 65
  • 1
  • 7

1 Answers1

3

You can't mix base graphics with lattice graphics which you are trying to do here (well, you can but not easily and not in the manner you are trying to do here).

One way is to use the grid.arrange() function in the gridExtra package, e.g.

## load packages required
library("HSAUR2")
library("Hmisc")
library("gridExtra")

## draw each plot separately and save to objects
plt1 <- Dotplot(latitude ~ mortality, data = USmelanoma)
plt2 <- Dotplot(longitude ~ mortality, data = USmelanoma)

## arrange the stored plots
grid.arrange(plt1, plt2, ncol = 2)

This gives:

enter image description here

This is an easy way to do what you want; there are other ways to do this directly with functions in the grid package itself, but they require a little more from the user.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453