0

I try to generate a histogram with 2 Y-axes. 1 Y-axe with the freq and 1 Y-axe with the cumulative freq in %. this is the closest I can get but it's a bit messy at the plot multiple labels on the axes, axis 4 not properly formatted

x<-rnorm(100,5,2)
hist(x,col=c("51"))
par(new=T)
plot(ecdf(x))
axis(4, at=1:10, col.ticks="red")
mean <- paste("mean = ", round(mean(x), digits = 4))
sd <- paste("sd = ", round(sd(x),digits = 4))
median <- paste("median = ", round(median(x),digits = 4)) 
legend(x = "topleft", c(mean,sd,median), bty = "n")

Thank in advance for your help,

Timon
  • 3
  • 3
  • `par(new=TRUE)`. See [this SO question](http://stackoverflow.com/questions/6142944/how-can-i-plot-with-2-different-y-axes). – r2evans May 14 '15 at 22:15
  • Probably need to ensure that the ranges of the two plots are identical, but the fact that hist sets its x values at interval midpoints and ecdf sets value at exact x-values means there is a bit of a disconnect. I tried a few efforts and they each had noticeable glitches (although they all looked better than yours.) – IRTFM May 14 '15 at 22:32
  • Thanks, I supressed the axes on the plot with axes=FALSE – Timon May 14 '15 at 22:49

0 Answers0