Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R barplot Y-axis scale too short

I'm trying to generate a barplot, but the y-axis scale is too short. Here's my code:

barplot(as.matrix(dat), log="y", ylim=c(10000,100000000), beside=TRUE,         ylab = "Number of reads", col = c("gray","black","white")) 

short y axis

It leaves the room for the axis (as per ylim), but doesn't fill in the actual axis. I've been through ?barplot and tried a few things (from googling around I thought xpd = F, yaxs = c(10000,10000000,5) should work, but it didn't).

I know it's a minor thing, but it's exactly the kind of problem I get stuck on for ages, instead of actually working, so any help would be much appreciated!

Edit: Cheers for the input guys!

I did initially plot without ylim, but it ends up with an even more bizarre axis (with the same problem); I actually picked my ylim values to give it a nicer spaced axis. original no ylim

Here's the data:

dat <- read.table(text="D2,D3n,D3m,D4n,D4m 21234722,34262282,31920464,25486357,20712943 35343,64403,22537,39934,46547 126646,312286,101105,81537,76944", header=TRUE, sep=",") 

Edit 2: @DWin had it right - I updated my R, and now it plots fine - thanks everyone!

like image 984
jayemee Avatar asked Apr 20 '13 15:04

jayemee


People also ask

How do you make the Y axis longer in R?

Method 1: Change Axis Scales in Base R To change the axis scales on a plot in base R Language, we can use the xlim() and ylim() functions. The xlim() and ylim() functions are convenience functions that set the limit of the x-axis and y-axis respectively.

What is y axis scale?

(Default) A linear scale on the Y axis represents equal distance and change on a chart. So for example, if grid lines are enabled, a change of three spaces on a line graph may represent an increase of 3MB of data.

What is height in barplot?

11.5 Barplot: barplot() A barplot typically shows summary statistics for different groups. The primary argument to a barplot is height : a vector of numeric values which will generate the height of each bar. To add names below the bars, use the names.arg argument.


1 Answers

I see you try to set ylim but you give bad values. This will change the scale of the plot (like a zoom). For example see this:

par(mfrow=c(2,1)) tN <- table(Ni <- stats::rpois(100, lambda = 5)) r <- barplot(tN, col = rainbow(20),ylim=c(0,50),main='long y-axis') r <- barplot(tN, col = rainbow(20),main='short y axis') 

enter image description here Another option is to plot without axes and set them manually using axis and usr:

require(grDevices) # for colours par(mfrow=c(1,1)) r <- barplot(tN, col = rainbow(20),main='short y axis',ann=FALSE,axes=FALSE) usr <- par("usr") par(usr=c(usr[1:2], 0, 20)) axis(2,at=seq(0,20,5)) 

enter image description here

like image 71
agstudy Avatar answered Sep 22 '22 02:09

agstudy