[R] Plotting two y-axis vs non-numeric x-axis

David Winsemius dwinsemius at comcast.net
Sat Jun 15 18:20:34 CEST 2013


On Jun 15, 2013, at 5:18 AM, Birdada Simret wrote:

> Hi dear all, the following code is correct. but I want to use non-numeric
> x-axis, for example
> if I replace   time <- seq(0,72,6)  by
> month <-
> c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Pag")
> 
> Ofcourse I use factor(month)  instead of time; but I didn't get similar
> plot as the example shown. any help is greatful ;)

We are not seeing any example. Please read the documentation for the Rhelp mailing list more carefully. The information about attachments may not be in the PostingGuide but instead in the listinfo page.  (I for one do not understand what you are requesting.)
> 
> month <-
> c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Pag")
> music <- c(0.05,0.18,0.25,0.31,0.32,0.34,0.35,
> 0.36,0.37,0.38,0.39,0.40,0.41)
> actor <- c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000,11000,12000)
> par(mar=c(5, 4, 4, 4) + 0.1)
> plot(factor(month), music, pch=16, axes=F, ylim=c(0,1), xlab="", ylab="",
> type="b",col="black", main="Enjoy")
> axis(2, ylim=c(0,1),col="black")
> mtext("Music",side=2,line=2.5)
> box()
> par(new=T)
> plot(factor(month), actor, pch=15,  xlab="", ylab="", ylim=c(0,13000),
> axes=F,  type="b", col="red")
> mtext("Actor",side=4,col="red",line=2.5)
> axis(4, ylim=c(0,13000), col="red",col.axis="red")
> axis(1,pretty(range(month),10))
> mtext("Month",side=1,col="black",line=2.5)
> legend(5,13000,legend=c("Music","Actor"),text.col=c("black","red"),pch=c(16,15),col=c("black","red"))
> 
> 	[[alternative HTML version deleted]]

-- 

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list