1

I can't figure out why my values are out of order when I plot them. Ex. x axis 0 shows values for 0.2, x axis 0.2 shows values for 0.6, x axis 0.6 shows values for 1.2 and x axis 1.2 shows values for 0.

R version 2.15.2 (2012-10-26) -- "Trick or Treat" run on Mac OS X 10.6.8

method spike elisa kit fish spectral conc conc2

1   Mekebri CNTRL   AbraxisRBT abraxis rbt 450 0.0900000        0.09
2   Mekebri CNTRL   AbraxisRBT abraxis rbt 450 0.0700000        0.09
3   Mekebri CNTRL   AbraxisRBT abraxis rbt 450 0.0700000        0.08
4   Mekebri CNTRL    EnviroRBT enviro  rbt 450 0.0900000        0.09
5   Mekebri CNTRL    EnviroRBT enviro  rbt 450 0.0700000        0.09
6   Mekebri CNTRL    EnviroRBT enviro  rbt 450 0.0700000        0.08
7   Mekebri   0.2   AbraxisRBT abraxis rbt 450 0.1100000        0.12
8   Mekebri   0.2   AbraxisRBT abraxis rbt 450 0.3000000        0.32
9   Mekebri   0.2   AbraxisRBT abraxis rbt 450 0.1000000        0.10    
10  Mekebri   0.2    EnviroRBT enviro  rbt 450 0.1100000        0.12
11  Mekebri   0.2    EnviroRBT enviro  rbt 450 0.3000000        0.32
12  Mekebri   0.2    EnviroRBT enviro  rbt 450 0.1000000        0.10    
13  Mekebri   0.6   AbraxisRBT abraxis rbt 450 0.1600000        0.16
14  Mekebri   0.6   AbraxisRBT abraxis rbt 450 0.1800000        0.18
15  Mekebri   0.6   AbraxisRBT abraxis rbt 450 0.1700000        0.17
16  Mekebri   0.6    EnviroRBT enviro  rbt 450 0.1600000        0.16
17  Mekebri   0.6    EnviroRBT enviro  rbt 450 0.1800000        0.18
18  Mekebri   0.6    EnviroRBT enviro  rbt 450 0.1700000        0.17
19  Mekebri   1.2   AbraxisRBT abraxis rbt 450 0.9680557 0.963486175
20  Mekebri   1.2   AbraxisRBT abraxis rbt 450 0.6040148 0.622156567
21  Mekebri   1.2   AbraxisRBT abraxis rbt 450 0.5665602   0.5849501
22  Mekebri   1.2    EnviroRBT enviro  rbt 450 0.9680557 0.963486175
23  Mekebri   1.2    EnviroRBT enviro  rbt 450 0.6040148 0.622156567
24  Mekebri   1.2    EnviroRBT enviro  rbt 450 0.5665602   0.5849501

plot(c(0,0.2,0.6,1.2),
with(mc, tapply(conc2, list(kit,spike), mean,na.rm=T))[1,],
type="b",lwd=2,
ylim=c(0,1),
xlab=expression(paste("Spike, ",mu,"g / L")),
ylab=expression(paste(mu,"g / L")),
col="blue")
points(c(0,0.2,0.6,1.2),
with(mc, tapply(conc2, list(kit,spike), mean,na.rm=T))[2,],
type="b",lwd=2,
ylim=c(0,1),
col="red")
legend(0.2,0.8,lty=1,lwd=2,
col=c("blue","red"),legend=c("Abraxis","EnviroLogix"))

dput(head(mc))
structure(list(method = structure(c(3L, 3L, 3L, 3L, 3L, 3L), .Label = c("Geis", 
"Mag", "Mekebri"), class = "factor"), spike = structure(c(4L, 
4L, 4L, 4L, 4L, 4L), .Label = c("0.2", "0.6", "1.2", "CNTRL"), class = "factor"), 
elisa = structure(c(2L, 2L, 2L, 2L, 2L, 1L), .Label = c("AbraxisBlank", 
"AbraxisRBT", "EnviroBlank", "EnviroRBT"), class = "factor"), 
kit = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Abraxis", 
"Enviro"), class = "factor"), fish = structure(c(2L, 2L, 
2L, 2L, 2L, 1L), .Label = c("blank", "rbt"), class = "factor"), 
spectral = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("450", 
"600", "scan"), class = "factor"), conc = structure(c(1L, 
1L, 1L, 8L, 1L, 2L), .Label = c("> DL", ">DL", "0", "0.01", 
"0.02", "0.03", "0.04", "0.05", "0.06", "0.07", "0.08", "0.09", 
"0.1", "0.11", "0.12", "0.13", "0.14", "0.15", "0.16", "0.17", 
"0.18", "0.19", "0.2", "0.21", "0.22", "0.23", "0.24", "0.25", 
"0.26", "0.27", "0.28", "0.29", "0.294871066", "0.3", "0.308253804", 
"0.31", "0.32", "0.33", "0.34", "0.344304772", "0.35", "0.350277282", 
"0.353189188", "0.359024076", "0.36", "0.360435916", "0.37", 
"0.370993533", "0.37858631", "0.378888547", "0.38", "0.384568909", 
"0.39", "0.4", "0.401289641", "0.41", "0.42", "0.43", "0.44", 
"0.45", "0.46", "0.47", "0.473548535", "0.48", "0.489942496", 
"0.49", "0.5", "0.51", "0.52", "0.53", "0.54", "0.55", "0.56", 
"0.566560247", "0.57", "0.58", "0.5849501", "0.6", "0.604014755", 
"0.61", "0.62", "0.622156567", "0.64", "0.65", "0.66", "0.67", 
"0.69", "0.7", "0.71", "0.73", "0.75", "0.77", "0.78", "0.79", 
"0.8", "0.81", "0.82", "0.83", "0.84", "0.85", "0.87", "0.88", 
"0.9", "0.91", "0.92", "0.963486175", "0.968055663", "0.97", 
"0.98", "1", "1.01", "1.02", "1.03", "1.04", "1.1", "1.11", 
"1.2"), class = "factor"), conc2 = c(0, 0, 0, 0.05, 0, 0)), .Names = c("method", 
"spike", "elisa", "kit", "fish", "spectral", "conc", "conc2"), row.names = c(NA, 
6L), class = "data.frame")
Ellen
  • 130
  • 3
  • 12
  • 2
    Please make this reproducible. See here: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Matthew Lundberg Mar 10 '13 at 23:13
  • 3
    When this happens to me it's usually because one of the columns is unexpectedly of the class `factor`. Can you paste in to your question the results of `dput(head(mc))` so we can check? – Ben Mar 10 '13 at 23:16
  • Hopefully I added enough info now... – Ellen Mar 10 '13 at 23:55
  • The data you have listed is one column short of that in your `dput(...)` output. – mnel Mar 11 '13 at 00:22

1 Answers1

3

It looks like you want the CNTRL level of your spike variable to correspond to zero, but that's not the order the factor levels are in. Try

mc <- transform(mc,spike=factor(spike,levels=c("CNTRL","0.2","0.6","1.2")))
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • glad it worked. You may (but are not required to) click on the checkmark next to the answer to mark it as the accepted answer ... – Ben Bolker Mar 11 '13 at 03:39