Question: R: scaling axis for different limits in hist
0
16 months ago by
johnnytam100100
johnnytam100100 wrote:

I am plotting several frequency plots using `hist` in R.

For different plots, there is a different maximum value for the y-axis, e.g.

Plot 1:15000 as max
Plot 2: 80000 as max

However, as a different limit of the axis was set, the physical lengths of the y-axes of the two graphs were different.

I want to make the y-axis into the same physical length.

Example of my scripts:

``````hist(perc1, breaks=seq(0,100,by=0.1), ylim=c(0,15000), xlab="percentage identity")
hist(perc2, breaks=seq(0,100,by=0.1), ylim=c(0,80000), xlab="percentage identity")
``````

Any idea how to modify the scripts? Thank you!

hist R • 480 views
modified 16 months ago by zx87549.1k • written 16 months ago by johnnytam100100

Unlikely, the size of plots (cm/inches) depend on the viewer (pdf, png, jpeg, etc functions) size, not on axis limits, could you explain how you are getting different "physical lengths", and what you mean by "physical lengths"?

Sorry for confusing by the term I used. The "physical lengths" means the height of the axis.

If you mean you want 2 plots to be on the same scale, then maybe use the same xlim?

1
16 months ago by
Belgium
WouterDeCoster43k wrote:

This is not strictly bioinformatics, but rather programming and would, therefore, fit better on StackOverflow, but I think the following should work:

``````png(filename="your/file/location/name1.png", width=5, height=10, units="cm")
hist(perc1, breaks=seq(0,100,by=0.1), ylim=c(0,15000), xlab="percentage identity")
dev.off()

png(filename="your/file/location/name2.png", width=5, height=10, units="cm")
hist(perc2, breaks=seq(0,100,by=0.1), ylim=c(0,80000), xlab="percentage identity")
dev.off()
``````