'R histogram plotting

I have a problem with my R double histogram. I am adding two hist on the same plot, and for some reason the top part of the graph is cut off. I am simply trying to fit all the 'bars' within the plot. Can anyone please help? the graph currently looks like this, cut off at the top

mut <- subset(data_age, data_mutant =="Mutated")
notmut <- subset(data_age, data_mutant =="not mutated")

set.seed(100)
p1 <- hist(mut, plot=F)                   
p2 <- hist(notmut,plot=F)                     
plot( p1, col=rgb(0,0,1,1/4), xlim=range(c(mut,notmut)))  
plot( p2, col=rgb(1,0,0,1/4), xlim=range(c(mut,notmut)), add=T)

the graph currently looks like this, cut off at the top



Solution 1:[1]

Add a ylim as well.

p1 <- hist(mut, plot=F)                   
p2 <- hist(notmut,plot=F)                     
plot( p1, col=rgb(0,0,1,1/4), xlim=range(c(mut,notmut)), ylim=range(c(p1$counts,p2$counts)))  
plot( p2, col=rgb(1,0,0,1/4), add=T)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1