Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot Only to Portion of Barplot

Tags:

r

bar-chart

How can I plot only the top portion of a barplot so as to emphasize the difference between the bars without manually calculating the differences and plotting these. I care about the actual values and would thus prefer if these were on the y-axis. It seems like there should be an easy way to accomplish this. If not, I can plot differences and manually change the values which appear on the y-axis.

By changing the ylim I can display the portions of the barplot that have variation, like I want, but part of the bars go through my margins.

barplot(c(54.0, 56.7, 55.9, 59.0), ylim=c(50,60))

The original, less informative plot:

barplot(c(54.0, 56.7, 55.9, 59.0))

Thanks for any help!

like image 979
Michael Davidson Avatar asked Feb 24 '26 10:02

Michael Davidson


1 Answers

Try xpd = FALSE in your call:

barplot(c(54.0, 56.7, 55.9, 59.0), ylim=c(50,60), xpd = FALSE)
box() #maybe nicer if you add this too

HTH

like image 182
sparrow Avatar answered Feb 27 '26 02:02

sparrow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!