Skip to content

Plotting two y-axis vs non-numeric x-axis

6 messages · Birdada Simret, David Winsemius, arun +1 more

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

            
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.)

  
    
#
Hi,

You could use ?twoord.plot() from library(plotrix):
library(plotrix)
dat2<- data.frame(month,music,actor)
dat2$month<- factor(month,labels=c(month.abb,"Pag"))
dat2New<-dat2[order(dat2$month),]

?with(dat2New,twoord.plot(month,music,actor,
??????????????????????? lylim=c(0,1),rylim=c(0,13000),
??????????????????????? ylab="Music",
??????????????????????? rylab="Actor",main="Enjoy",
??????????????????????? type=c("p","b"),lcol=1,rcol="red",xtickpos=month,xticklab=month))
???? legend(5,13000,legend=c("Music","Actor"),text.col=c("black","red"),col=c("black","red"))?? 

#I tried to change the plotting symbol using "pch" inside the twoord.plot(), but it seems to be not working. 
?with(dat2New,twoord.plot(month,music,actor,
???????????????????????? lylim=c(0,1),rylim=c(0,13000),
???????????????????????? ylab="Music",
???????????????????????? rylab="Actor",main="Enjoy",
???????????????????????? type=c("p","b"),pch=c(1,4),lcol=1,rcol="red",xtickpos=month,xticklab=month))
#Error in localWindow(xlim, ylim, log, asp, ...) : 
?# formal argument "pch" matched by multiple actual arguments

A.K.
?????????????? 


----- Original Message -----
From: Birdada Simret <birdada85 at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Saturday, June 15, 2013 8:18 AM
Subject: [R] Plotting two y-axis vs non-numeric x-axis

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 ;)

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]]

______________________________________________
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.
#
On Jun 15, 2013, at 11:14 AM, Birdada Simret wrote:

            
Er, Not really. The error was the line above that warning:

"Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf"

You are sending a character vector to plot() as the first argument, and plotting dispatch system cannot find a 'plot.character' method so it sends it to 'plot.default' which is expecting a numeric vector for x and things all fall apart from there.

You could use: seq_along(month)  # instead of month

(And obviously the xlab would need to be changed, since you are no longer working with "Hours".)

And. Please learn to post in plain text.

-- David
David Winsemius
Alameda, CA, USA
#
On 06/16/2013 04:14 AM, Birdada Simret wrote:
Hi Birdada,
You can get the month labels using something like this:

twoord.plot(time,music,time,actor,lylim=c(0,1),type=c("l","b"),
  xtickpos=seq(0,70,by=10),xticklab=month.abb[1:8])

Hi arun,
This question may already have been answered, but to change the symbols, 
you have to use "lpch=" and "rpch=". I get the appropriate types of plot 
when using the above, and I tried several combinations of point, line, 
both that all worked okay. If I figure out what happened in your example 
I'll email the answer.

Jim