Phaml - 6 months ago 39

R Question

I am plotting a histogram of actual data along with a density plot on the same graph but the x axis and y axis all mixed up. Is there a way to make sure the graph has the same axis e.g set a range to the graph for both the plot.

The reason that I put histogram and density plot together is for comparisons. The data range for both plots are similar but they alway produce two labels on the same axis making it unreadable.

`a <- rnorm(100, 3, 7)`

x <- c(0:200)

plot(0.5 * dpois(x, 4) + ((1 - 0.5) * dpois(x, 2)))

lines(0.5 * dpois(x, 4) + ((1 - 0.5) * dpois(x, 2)))

par(new = TRUE)

hist(a)

Answer

Since nobody answers my question. I have figured it out.

set the same `xlim`

and `ylim`

to **both** graph which makes aligned the x,y axes.