[R] xlim with barplot

arun smartpink111 at yahoo.com
Mon Sep 23 05:56:29 CEST 2013


You could try ggplot() as well.
library(ggplot2)
library(gridExtra)
library(plyr)
x1<- count(x)
 y1<- count(y)
p1<-ggplot(x1,aes(x=x,y=freq))+geom_bar(stat="identity",colour="gray",fill="red")+xlim(c(35,85))+ theme_bw()+ theme(axis.line=element_line(colour="black"),
panel.grid.major=element_blank(), panel.grid.minor=element_blank(), panel.border=element_blank(),panel.background=element_blank())
 p2<-ggplot(y1,aes(x=x,y=freq))+geom_bar(stat="identity",colour="gray",fill="blue")+xlim(c(35,85)) +theme_bw()+ theme(axis.line=element_line(colour="black"),
panel.grid.major=element_blank(), panel.grid.minor=element_blank(), 
panel.border=element_blank(),panel.background=element_blank())
 grid.arrange(p1,p2,nrow=2)

A.K.



----- Original Message -----
From: David Arnold <dwarnold45 at suddenlink.net>
To: r-help at r-project.org
Cc: 
Sent: Sunday, September 22, 2013 10:55 PM
Subject: [R] xlim with barplot

Hi,

I want to compare to barplots with same horizontal axis limits.

x=c(55,56,57,58,59,60,60,60,61,62,63,64,65)
y=c(35,40,45,50,55,60,60,60,65,70,75,80,85)

par(mfrow=c(2,1))
barplot(table(x),xlim=c(35,85))
barplot(table(y),xlim=c(35,85))
par(mfrow=c(1,1))

But the bars disappear.

<http://r.789695.n4.nabble.com/file/n4676717/Rplot.png> 

Any suggestions?






--
View this message in context: http://r.789695.n4.nabble.com/xlim-with-barplot-tp4676717.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