Skip to content
Prev 62780 / 398500 Next

Plots with same x-axes

On Fri, 2005-01-21 at 01:48 +0100, Robin Gruna wrote:
Robin,

Here is an example:

# Set the layout, smaller plot on top for the 
# barplot region
nf <- layout(c(2, 1), heights = c(1, 3))
layout.show(nf)

# Create the data
x <- rnorm(50)
y <- rnorm(50)

# Set the margins for the scatterplot so that they will match with the
# barplot settings
par(mar = c(3, 3, 0, 3))

# now do the scatterplot
plot(x, y)

# Get the hist data for x
xhist <- hist(x, plot = FALSE)

# Set the margins for the barplot to use more of the plot
# region
par(mar = c(0, 3, 1, 3))

# now plot that barplot on top
# Set the 'space' argument to 0 so that the bars are
# next to each other
barplot(xhist$counts, axes = FALSE, space = 0)

HTH,

Marc Schwartz