我如何自定义r leveltot中的loress fit r r r r r r r r r r r r r in

发布于 2025-02-10 17:05:51 字数 1539 浏览 0 评论 0 原文

我在R中创建了一个LevelPlot,它使用此代码显示了我的数据叠加在平滑轮廓图上的数据:

levelplot(chla_avg ~ lat * depth, trunc_level_test, ylim = c(275, 5), region = TRUE, col.regions = hcl.colors(110, palette = "spectral",rev=F), contour = FALSE, cuts = 100, panel = panel.levelplot.points) +
  layer_(panel.2dsmoother(..., n = 400, method = 'loess'))

这会产生此图像: levelplot

我喜欢这张图。它完全显示了我想要的 ,我不喜欢黄土模型的合适。正常我可以自定义 loess(),但我无法弄清楚如何获得 panel.2dsmoother()来获取我的参数。理想情况下,我想更改 span loess()的参数,以使拟合度降低一点。

我已经尝试过:

levelplot(chla_avg ~ lat * depth, trunc_level_test, ylim = c(275, 5), region = TRUE, col.regions = hcl.colors(110, palette = "spectral",rev=F), contour = FALSE, cuts = 100, panel = panel.levelplot.points) +
  layer_(panel.2dsmoother(..., n = 400, method = 'loess(span=0.1)'))

哪个产生此错误:

Error using packet 1
could not find function "loess(span=0.1)"

清楚面板。2DDSMOOTHER正在以我不理解的方式重新解释该功能。

panel.2DSMOOTHOR 文档中说:“平滑模型是构建(大约)为方法(form,data = list = list(x = x,y = y,z = z), {args})。” ( loess 函数。

无论如何,是否可以在 panel内部自定义黄土。2DDSMOOTHOR

I have created a levelplot in R that displays my data overlayed on a smoother contour plot using this code:

levelplot(chla_avg ~ lat * depth, trunc_level_test, ylim = c(275, 5), region = TRUE, col.regions = hcl.colors(110, palette = "spectral",rev=F), contour = FALSE, cuts = 100, panel = panel.levelplot.points) +
  layer_(panel.2dsmoother(..., n = 400, method = 'loess'))

This produces this image:
levelplot

I love this graph. It displays exactly what I want except I don't love the fit of the loess model. Normal I could customize loess() but I can't figure out how to get panel.2dsmoother() to take my arguments. Ideally I would like to change the span and degree arguments of loess() to make the fit a little less smooth.

I've tried:

levelplot(chla_avg ~ lat * depth, trunc_level_test, ylim = c(275, 5), region = TRUE, col.regions = hcl.colors(110, palette = "spectral",rev=F), contour = FALSE, cuts = 100, panel = panel.levelplot.points) +
  layer_(panel.2dsmoother(..., n = 400, method = 'loess(span=0.1)'))

Which produces this error:

Error using packet 1
could not find function "loess(span=0.1)"

Clearly panel.2dsmoother is reinterpreting the function in a way I do not understand.

In the panel.2dsmoother documentation it says: "the smoothing model is constructed (approximately) as method(form, data = list(x=x, y=y, z=z), {args})." (panel.2dsmoother documentation) I cannot figure out how to pass my arguments to the loess function.

Is there anyway to customize loess inside panel.2dsmoother?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尘世孤行 2025-02-17 17:05:51

您可以使用 args panel.2dsmoother 的参数将额外的参数传递到 loess 方法。只需将参数放入列表中即可。

显然,我们没有您的数据,但是我们可以使用内置数据集 iris 来显示概念。首先,我们将以默认参数向图显示:

library(lattice)
library(latticeExtra)

levelplot(Sepal.Width ~ Petal.Width * Petal.Length, 
          iris,
          region = TRUE, 
          col.regions = hcl.colors(110, palette = "spectral", rev = F), 
          contour = FALSE) +
  layer_(panel.2dsmoother(..., n = 400, method = 'loess'))

”在此处输入图像描述“

现在让我们使用较小的 span 为我们的羊皮平滑值:

levelplot(Sepal.Width ~ Petal.Width * Petal.Length, 
          iris,
          region = TRUE, 
          col.regions = hcl.colors(110, palette = "spectral", rev = F), 
          contour = FALSE) +
  layer_(panel.2dsmoother(..., n = 400, method = 'loess', 
                         args = list(span = 0.2)))

You can pass extra arguments to the loess method using the args parameter of panel.2dsmoother. Just put the arguments inside a list.

Obviously, we don't have your data, but we can show the concept using the built in data set iris. First, we'll show the plot with the default arguments:

library(lattice)
library(latticeExtra)

levelplot(Sepal.Width ~ Petal.Width * Petal.Length, 
          iris,
          region = TRUE, 
          col.regions = hcl.colors(110, palette = "spectral", rev = F), 
          contour = FALSE) +
  layer_(panel.2dsmoother(..., n = 400, method = 'loess'))

enter image description here

Now let's use a smaller span value for our loess smoothing:

levelplot(Sepal.Width ~ Petal.Width * Petal.Length, 
          iris,
          region = TRUE, 
          col.regions = hcl.colors(110, palette = "spectral", rev = F), 
          contour = FALSE) +
  layer_(panel.2dsmoother(..., n = 400, method = 'loess', 
                         args = list(span = 0.2)))

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文