R: scaling axis for different limits in hist
1
0
Entering edit mode
5.4 years ago
johnnytam100 ▴ 110

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 • 5.6k views
ADD COMMENT
0
Entering edit mode

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 REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode
5.4 years ago

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 COMMENT
0
Entering edit mode

Thanks Wouter! I will post on stackoverflow next time.

ADD REPLY

Login before adding your answer.

Traffic: 2630 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6