Manish Gupta
2012-Aug-01 07:38 UTC
[R] How to increase lenght of axis according input data?
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.
Anders Ellern Bilgrau
2012-Aug-01 09:39 UTC
[R] How to increase lenght of axis according input data?
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.
Jean V Adams
2012-Aug-01 13:10 UTC
[R] How to increase lenght of axis according input data?
You could use the xlim argument to barplot. For example, barplot(t(data[,2:3]), beside=TRUE, xlim=c(0, 20), 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) Jean Manish Gupta <mandecent.gupta@gmail.com> wrote on 08/01/2012 02:38:42 AM:> > Hi, > > I am working on barplot. I need to plot x-axis but scale on x axis isvery> 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?[[alternative HTML version deleted]]