Question: R: scaling axis for different limits in hist
0
gravatar for johnnytam100
12 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 • 353 views
ADD COMMENTlink modified 12 months ago by zx87548.7k • written 12 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"?

ADD REPLYlink written 12 months ago by zx87548.7k

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

ADD REPLYlink written 12 months ago by johnnytam100100

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

ADD REPLYlink written 12 months ago by zx87548.7k
1
gravatar for WouterDeCoster
12 months ago by
Belgium
WouterDeCoster42k 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()
ADD COMMENTlink written 12 months ago by WouterDeCoster42k

Thanks Wouter! I will post on stackoverflow next time.

ADD REPLYlink written 12 months ago by johnnytam100100
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 743 users visited in the last hour