The major problem is all the padding and the LF in the level names.
This repair is based on the ?gsub example on "## trim trailing white space".

levels(bdf$func_feed_grp)
## [1] " Filterer\n"     " Gatherer      " " Grazer        " " Omnivore
 "
## [5] " Parasite      " " Predator      " " Shredder      "
levels(bdf$func_feed_grp) <- sub("^[[:space:]]+", "", sub("[[:space:]]+$",
"", levels(bdf$func_feed_grp) )) ## white space, POSIX-style
levels(bdf$func_feed_grp)
## [1] "Filterer" "Gatherer" "Grazer"   "Omnivore" "Parasite" "Predator"
"Shredder"


I switched the key to "lines" to match the graph.

You need to control the color choice differently when using a key.
It is discussed in ?xyplot in the paragraph
          Note that 'simpleKey' uses the default settings (see
          'trellis.par.get') to determine the graphical parameters in
          the key, so the resulting legend will be meaningful only if
          the same settings are used in the plot as well.  The
          'par.settings' argument may be useful to temporarily modify
          the default settings for this purpose.


xyplot(pct ~ sampdate, data = bdf, groups = func_feed_grp, type = 'l',
       key = simpleKey(text = levels(bdf$func_feed_grp), space ='right',
points=FALSE, lines=TRUE),
       par.settings=list(superpose.points=list(col=rainbow(7)),
superpose.lines=list(col=rainbow(7))))


Rich



On Fri, Aug 16, 2013 at 10:49 AM, Rich Shepard <rshepard@appl-ecosys.com>wrote:

> On Thu, 15 Aug 2013, Rich Shepard wrote:
>
>  Now I see the source of my error: I quoted the data file name! Removing
>> the quotation marks produces the plots.
>>
>
>   Thanks to A.K. and Dennis Murphy I understand how to plot the data in
> these data sets. However, I am not getting the colors within the plot to
> match those in the key despite reading about using color pallettes and
> experimenting with pallettes and various numbers of colors. Since I don't
> see what I'm doing incorrectly I'd appreciate having someone point this out
> to me.
>
>   Data set:
>
>  dput(bdf)
>>
> structure(list(sampdate = structure(c(11156, 11156, 11156, 11156, 11156,
> 12241, 12241, 12241, 12241, 12241, 12977, 12977, 12977, 12977, 12977,
> 13327, 13327, 13327, 13327, 13327, 14866, 14866, 14866, 14866, 14866,
> 14866, 14866, 15168, 15168, 15168, 15168, 15168, 15168, 15170, 15170,
> 15170, 15170, 15170, 15170, 15170, 15532, 15532, 15532, 15532, 15532,
> 15532), class = "Date"), func_feed_grp =
> structure(c(1L, 2L, 3L, 6L, 7L, 1L, 2L, 3L, 6L, 7L, 1L, 2L, 3L, 6L, 7L,
> 1L, 2L, 3L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 1L,
> 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 6L, 7L), .Label = c(" Filterer
> ", " Gatherer      ", " Grazer        ", " Omnivore      ", " Parasite
>  ", " Predator      ", " Shredder      "), class = "factor"), pct =
> c(0.0351, 0.7054, 0.0442, 0.1078, 0.1074, 0.157, 0.7039, 0.0023, 0.0456,
> 0.0912, 0.0293, 0.6634, 0.0055, 0.0552, 0.2466, 0.0414, 0.4776, 0.1033,
> 0.2012, 0.1765, 0.0811, 0.5785, 0.0284, 0.0131, 0.0018, 0.0736, 0.2234,
> 0.0041, 0.9011, 0.0563, 0.01, 0.0037, 0.0247, 0.0385, 0.8469, 0.0147,
> 5e-04, 0.0197, 0.0688, 0.0109, 0.1275, 0.503, 0.0257, 8e-04, 0.1464,
> 0.1966)), .Names = c("sampdate", "func_feed_grp", "pct"), row.names = c(NA,
> -46L), class = "data.frame")
>
>   The command I'm using to plot this data frame:
>
> xyplot(pct ~ sampdate, data = bdf, groups = func_feed_grp, type = 'l', col
> =
> rainbow(8), key = simpleKey(text = levels(bdf$func_feed_grp), space =
> 'right'))
>
>   I've used rainbow(6) through rainbow(12) and cannont get it correct. A
> sample plot is attached. Notice for the left-most points (year 2000) there
> are 5 functional feeding groups in the data: gatherers (approximately 70
> percent), predators and shredders (approximately 10 percent each), grazers
> and scrapers (approximately 4 percent each). According to the key parasites
> are approximately 70 percent of those data and gatherers approximately 10
> percent. That's not correct.
>
> Rich
> ______________________________________________
> R-help@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.
>
>

	[[alternative HTML version deleted]]

