From: Attiglah, Mama <Mama_Attiglah_at_ssga.com>

Date: Tue, 29 Jan 2008 17:17:11 -0000

Mama Attiglah, PhD

Advanced Research Center

Quantitative Research Analyst

State Street Bank

+44(0)20 7698 6290 (Direct Line)

*+44 (0)207 004 2968 (Direct Fax)
*

Please visit our Web site at

www.ssga.com

cbind(y1,y2,x)->mydata

data.frame(mydata)->mydata

with(mydata, tapply(y1,x,mean))->mean.y1 with(mydata, tapply(y2,x,mean))->mean.y2 #Barplot

par(mar=c(5,4,4,4)+0,1)

barplot(mean.y1,density=1,las=1)

par(new=T)

barplot(mean.y2,density=3,angle=3,axes=F) axis(4,las=1)

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.

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. Received on Tue 29 Jan 2008 - 17:20:33 GMT

Date: Tue, 29 Jan 2008 17:17:11 -0000

Try this

X = rbind(y1, y2)

colnames(X) = as.character(x)

barplot( X, density=c(35,40), col=c("red","blue"), beside=FALSE) barplot( X, density=c(35,40), col=c("red","blue"), beside=TRUE)

Alternatively,

barplot( y1, ylim = c(0, max(y1,y2)), col="blue", beside=FALSE)

par(new=TRUE)

barplot( y2, ylim = c(0, max(y1,y2)), col="red", beside=FALSE, names.arg=as.character(x))

Mama

Mama Attiglah, PhD

Advanced Research Center

Quantitative Research Analyst

State Street Bank

+44(0)20 7698 6290 (Direct Line)

Please visit our Web site at

www.ssga.com

-----Original Message-----

From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org]
On Behalf Of Gustaf Granath

Sent: 29 January 2008 16:15

To: r-help_at_r-project.org

Subject: [R] How to get two y-axises in a bar plot?

Hi,

I have measured two response variables (y1, y2) at each treatment level
(x = 0, 1.5 or 3). Now I would like to show the y1 and y2 against x in a

bar plot. However, y1 and y2 differ in scale so I need two y-axises, one

For code and data, see below.

Cheers,

Gustaf Granath, phd student

My code so far:

#Creating data

c(6.34,13.38,17.87)->y1 c(0.85,1.88,2.33)->y2 c(0,1.5,3)->x

cbind(y1,y2,x)->mydata

data.frame(mydata)->mydata

with(mydata, tapply(y1,x,mean))->mean.y1 with(mydata, tapply(y2,x,mean))->mean.y2 #Barplot

par(mar=c(5,4,4,4)+0,1)

barplot(mean.y1,density=1,las=1)

par(new=T)

barplot(mean.y2,density=3,angle=3,axes=F) axis(4,las=1)

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.

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. Received on Tue 29 Jan 2008 - 17:20:33 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Tue 29 Jan 2008 - 17:30:08 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*