Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R bar plot: how to set specified number in y axis but do not change the distance between numbers in R

I want to customized the y axis to a certain number, but the distance in the y axis should not be changed accordingly like below figure. I tried different way, but failed. Basically, when I use the axis(2, yseries), the y range will be changed.

The core I tried is like this:

yseries <- c(10,
             20,
             40,
             80,
             160,
             320,
             640,
             1280)

gm <- c(760, 640)
barplot(gm, xaxt = "n", yaxt = "n")
# Y-axis
axis(2, at = yseries)

You can see the y axis is different from the attached figure (where the y ranges from 10 to 1280, but the distance in the y axis is not changed in this figure. I also want to make this kind of figure). Can you help me to figure out?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks,

This is the figure I want to replicate it in y axis

>Solution :

You can set the range of the y axis in the plot command, and use a log scale to get equal distances between multiples as follows:

barplot(gm, xaxt = "n", yaxt = "n", log="y", ylim = range(yseries))
axis(2, at = yseries,las=1)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading