[R] How to increase lenght of axis according input data?

Anders Ellern Bilgrau anders.ellern.bilgrau at gmail.com
Wed Aug 1 11:39:12 CEST 2012


Hello,

Here's a quick and dirty solution. By setting axes = FALSE in the barplot plot arguments we suppress the axes. You then use the axis function afterward to draw the desired axis. Below, i have also used the pretty function.

Have a look at this:

data <- rbind(c(3,4,6), c(5,15,19))

pdf("image.pdf", width=10 , height =13)
par(mar=c(5,22.5,2,2))
barplot(t(data[,2:3]), beside=TRUE, col=c(rgb(.537, .769, .933),rgb(.059,
.412, .659)), width = 1, horiz=TRUE, cex.names=.9, border ="white",las=1,
cex.axis= 1, cex.lab=1.2, axes = FALSE, xlim = range(pretty(c(0, max(data)))))
axis(1, at = pretty(c(0, max(data))))
legend("topright", c("X","Y"), cex=1.5, bty="n", fill = c(rgb(.059, .412,
.659),rgb(.537, .769, .933)));
abline(v = 0, lwd = 1, col = 1)
dev.off()

Best regards,
Anders E Bilgrau



On 01/08/2012, at 09.38, Manish Gupta <mandecent.gupta at gmail.com> wrote:

> Hi,
> 
> I am working on barplot.  I need to plot x-axis but scale on x axis is very
> upto 15 while my data is upto 19.
> 
> pdf("image.pdf", width=10 , height =13)
> par(mar=c(5,22.5,2,2))
> barplot(t(data[,2:3]),   beside=TRUE, col=c(rgb(.537, .769, .933),rgb(.059,
> .412, .659)), width = 1, horiz=TRUE,cex.names=.9, border ="white",las=1,
> cex.axis= 1, cex.lab=1.2)
> legend("topright", c("X","Y"), cex=1.5, bty="n", fill = c(rgb(.059, .412,
> .659),rgb(.537, .769, .933)));
> abline(v = 0, lwd = 1, col = 1)
> dev.off()
> 
> http://r.789695.n4.nabble.com/file/n4638634/Screenshot.png 
> 
> How can i stretch x axis upto max input value?
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-increase-lenght-of-axis-according-input-data-tp4638634.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list