Skip to content

Plotting numeric values against non numeric items

8 messages · lse1986, Jim Lemon, jim holtman +3 more

#
Hi i want do a line graph.

My y axis contains numeric values. My x axis contains non numeric
statements.

This is what i want the graph to look like.

When i try to plot this graph on R it comes up with the following error
message:

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

Any help would be much appreciated. Thanks in advance.
#
On 01/09/2010 12:38 PM, lse1986 wrote:
Hi Sam,
While I don't know what you want the graph to look like, I would suggest 
the following:

xf<-factor(x)
plot(as.numeric(xf),rnorm(10),type="l",xaxt="n")
axis(1,at=1:10,labels=xf)

Jim
#
Hey Jim,

Thanks for your reply!

I tried what you said, i still kept getting errors.

here's what i want my graph to look like:

http://i.imagehost.org/0474/Untitled_5.jpg

i have x<-c("not stir", "stir")

i can't plot it though :(
Jim Lemon wrote:

  
    
#
On 01/10/2010 01:29 AM, lse1986 wrote:
Oh, I see.

AandC<-data.frame('Not Stir'=c(686.36,398.32),Stir=c(179.17,60.29))
rownames(AandC)<-c("Cube","Granules")
AandC
x11(height=3)
layout(matrix(1:2,1,2),c(1,2),c(1,1))
par(mar=c(1,0,0,0))
plot(0,type="n",axes=FALSE,xlab="",ylab="")
par(xpd=TRUE)
text(1,0.5,"A and C",cex=1.5)
par(xpd=FALSE)
library(plotrix)
addtable2plot(1,0,AandC,xjust=0.5,yjust=0.5,bty="o",hlines=TRUE,
  display.rownames=TRUE,cex=0.8)
par(mar=c(2,5,4,6),las=1,xaxs="i",yaxs="i",tcl=-0.2)
matplot(t(AandC),xlim=c(0.7,2.3),ylim=c(0,800),type="n",
  main="Dissolving time vs stirring/not stirring\nfor sugar cubes and 
granules",
  ylab="Dissolving time (seconds)",cex=0.8,
  axes=FALSE)
fullaxis(1,at=c(0.7,1.5,2.3),labels=c("","",""))
mtext(c("Not stir","Stir"),1,at=1:2)
axis(2,at=seq(0,800,by=100),cex=0.8)
grid(nx=0,ny=8,lty=1)
matpoints(t(AandC),type="o",col=c(4,2),pch=c(18,15),lty=1,lwd=2)
par(xpd=TRUE)
legend(2.7,400,c("Cubes","Granules"),pch=c(18,15),col=c(4,2),
  bty="n",lwd=2,lty=1,xjust=0.5,yjust=0.5,cex=0.8)
rect(0.1,-130,3,1100)
par(xpd=FALSE)

Jim
#
Dennis and Sam,

Re Dennis' lattice plot:
Here's how you can superpose lines and points in the key.
simpleKey() is not flexible enough, so we use the key list directly.

dissolve <- data.frame(
           Method = rep(c('No Stir', 'Stir'), each = 2),
           Type = rep(c('Cube', 'Granules'), 2),
           Time = c(686.36, 398.32, 179.17, 60.29))

library(lattice)
xyplot(Time ~ Method, data = dissolve, groups = Type,
        col = c('blue', 'red'), pch = c(16, 17), cex = 1.4, lwd = 2,
        ylim = c(0, 800),
        type = 'b',
        panel = function(x, y, ...) {
                        panel.grid(h = 7, v = 0)
                        panel.xyplot(x, y, ...)  },
        key = list(lines = list(col=c('blue','red'),
                                pch=c(16,17), type='b', lwd=2),
                   text = list(c('Cube', 'Granules')),
                   divide = 1,
                   size = 3,
                   space = 'right'),
        scales = list(tck = c(1, 0),
                      x = list(at = c(1, 2),
                          labels = c('No stir', 'Stir')),
                      y = list(at = seq(0, 800, by = 100))),
        main = 'Dissolving time vs. Stirring / No stirring\n
                for sugar cubes and granules',
        ylab = 'Dissolving time (seconds)')

The 'size' and 'divide' arguments to key set the length of
the line and the number of points overlapping it, for which
the default seems to be 3.

Another comment re Dennis' code: the par.settings() line
won't work as given; you need either

   par.settings = simpleTheme(col = c('Blue', 'Red')),

or

   par.settings = list(superpose.line = list(col = c('Blue', 'Red')),
                       superpose.symbol = list(col = c('Blue', 'Red'))),

but neither is needed.

  -Peter Ehlers
Dennis Murphy wrote:

  
    
#
Check out the interaction.plot function.
On Fri, 8 Jan 2010, lse1986 wrote:
l > 
l > Hi i want do a line graph.
l > 
l > My y axis contains numeric values. My x axis contains non numeric
l > statements.
l > 
l > This is what i want the graph to look like.
l > 
l > When i try to plot this graph on R it comes up with the following error
l > message:
l > 
l > "Error in plot.window(...) : need finite 'xlim' values
l > In addition: Warning messages:
l > 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
l > 2: In min(x) : no non-missing arguments to min; returning Inf
l > 3: In max(x) : no non-missing arguments to max; returning -Inf"
l > 
l > Any help would be much appreciated. Thanks in advance.