Hi all, I want to plot two graphs and I use this : par(mar=c(10,6,6,6)) matplot(Simulation,type="l") abline(h = 0, lwd = 2, col = "black") fhist<-hist(Simulation,plot=FALSE) par(mar=c(6,0,6,6)) barplot(fhist$counts,axes=FALSE, space=0,horiz=TRUE,col="lightgray") The question is, that the legth of the hist plot is not equilibrated with the main plot so the fhist is not achiving the goal I?m looking so that it happens what I attach in png, it seems that the right plot is central value is below the value of the simulation. How can I ensure that de max min in the left is the same that in the right (second) plot? -------------- next part -------------- A non-text attachment was scrubbed... Name: adjust.png Type: image/png Size: 39511 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20151020/91b29ae2/attachment.png>
Hi bgnumis, I'm too lazy to try to work out what "Simulation" contains, but try this: Simulation<-sin(seq(0,6*pi,length.out=144))*5000+ 2000*runif(144)+seq(8000,5000,length.out=144) png("bb.png",width=800,height=400) par(mfrow=c(1,2)) plot(Simulation,type="l",ylim=c(0,20000)) abline(h = 0, lwd = 2, col = "black") fhist<-hist(Simulation,breaks=seq(0,20000,by=2000),plot=FALSE) barplot(fhist$counts,axes=FALSE, space=0,horiz=TRUE,col="lightgray") dev.off() Jim On Wed, Oct 21, 2015 at 3:27 AM, bgnumis bgnum <bgnumis at gmail.com> wrote:> Hi all, > > I want to plot two graphs and I use this : > > par(mar=c(10,6,6,6)) > matplot(Simulation,type="l") > > abline(h = 0, lwd = 2, col = "black") > > fhist<-hist(Simulation,plot=FALSE) > par(mar=c(6,0,6,6)) > barplot(fhist$counts,axes=FALSE, space=0,horiz=TRUE,col="lightgray") > > > The question is, that the legth of the hist plot is not equilibrated with > the main plot so the fhist is not achiving the goal I?m looking so that it > happens what I attach in png, it seems that the right plot is central value > is below the value of the simulation. How can I ensure that de max min in > the left is the same that in the right (second) plot? > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
> fhist<-hist(Simulation,plot=FALSE) > par(mar=c(6,0,6,6)) > barplot(fhist$counts,axes=FALSE, space=0,horiz=TRUE,col="lightgray")i) Unlike hist(), barplot() does not plot at histogram bin boundaries - you'll have noticed that you did not specify locations for the bars and in fact can not do so . There is no simple way of aligning a barplot with particular axis length and locations. But there is a useful example of usig rect() to do the job in ?pairs; look for the USJudgeRatings example and see the panel.hist function there. It should be straightforward to adapt that for horizontal use. ii) axes= has nothing to do with the plot limits. xlim and ylim control plot limits. You should set ylim and the top and bottom margins to the same values for both plots. iii) Your png file includes a barplot with gridlines, so that cannot be the result of the exact command you used above. If you used a different plotting system for the bar plot the alignment would be very hard to guarantee, so stay with base graphics for both. S Ellison ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}