lost_river at excite.com
2008-Dec-21 19:49 UTC
[R] Trouble with 'smooth' using xyplot in lattice
Hello,
I am fairly new to R am stumped on how to get the xyplot function in the lattice
package to produce a scatter plot of count data versus time, such that the count
data represent 8 different groups, and the plot produced has 8 unique
"smoothed" lines for the different groups. This is the closest I can
get to the desired plot:
xyplot(masmean ~ mas, data = Pre96CR.masmeans, groups = behavior,
type = 'smooth', span = 0.3, lwd =2,
xlab = "Minutes After Sunrise", ylab = "Behaviors at
Castle"
key = simpleKey(levels(Pre96CR.masmeans$behavior), space =
'right'))
This code produces a plot, but one level of the grouping factor
('behavior') is always absent from the plot and in the middle of the
plot I receive an error message:
Error using packet 1
NA/NaN/Inf in foreign function call (arg 1)
Otherwise, the plot is exactly what I want with smoothed lines produced for the
7 other levels of "behavior". Thanks in advance for any
ideas/suggestions.
Cheers,
Peter
------------------------------------------------------------
Auto Insurance
Click to get a free auto insurance quotes from top companies.
http://tagline.excite.com/fc/BK72PcZaarRjzT3NanuZSqmiJRbhpHy3XCE7MhKHfzwJU7fMMxfSz2/
[[alternative HTML version deleted]]
Peter,
The error message comes from panel.loess, which is the panel function
that draws the Loess smoothing line. It means one of your groups has
too few data points or is too clustered in its domain for the Loess
smoother to converge.
You could
- give up on the pretty-looking smoother
- increase the span; or
- ignore the error, with eg
lattice.options = list(panel.error = "warning")
In any case I would recommend plotting the data points, not just the
smoothed lines. You can set type = c("p", "smooth")
-Felix
2008/12/22 lost_river at excite.com <lost_river at
excite.com>:> Hello,
>
> I am fairly new to R am stumped on how to get the xyplot function in the
lattice package to produce a scatter plot of count data versus time, such that
the count data represent 8 different groups, and the plot produced has 8 unique
"smoothed" lines for the different groups. This is the closest I can
get to the desired plot:
>
> xyplot(masmean ~ mas, data = Pre96CR.masmeans, groups = behavior,
> type = 'smooth', span = 0.3, lwd =2,
> xlab = "Minutes After Sunrise", ylab = "Behaviors at
Castle"
> key = simpleKey(levels(Pre96CR.masmeans$behavior), space =
'right'))
>
> This code produces a plot, but one level of the grouping factor
('behavior') is always absent from the plot and in the middle of the
plot I receive an error message:
> Error using packet 1
> NA/NaN/Inf in foreign function call (arg 1)
> Otherwise, the plot is exactly what I want with smoothed lines produced for
the 7 other levels of "behavior". Thanks in advance for any
ideas/suggestions.
>
> Cheers,
> Peter
>
> ------------------------------------------------------------
> Auto Insurance
> Click to get a free auto insurance quotes from top companies.
>
http://tagline.excite.com/fc/BK72PcZaarRjzT3NanuZSqmiJRbhpHy3XCE7MhKHfzwJU7fMMxfSz2/
> [[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.
>
--
Felix Andrews / ???
http://www.neurofractal.org/felix/
3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8