Reputation: 159
This sounds like a really basic question and it probably is but I can't figure out how to change the line width when plotting a locfit
object. If you do a simple test, such as:
plot(locfit::locfit(~rnorm(n = 1000)))
and compare it with
plot(locfit::locfit(~rnorm(n = 1000)), lwd = 2.0)
You will see that the plotted line has the same thickness in both plots. So using lwd
does not work when plotting a locfit
object? Is there any workaround?
Thanks!
Upvotes: 1
Views: 65
Reputation: 41265
You could use your model to predict
the output to use lines
on an empty plot
which makes it possible to change the linewidth with lwd
like this:
library(locfit)
#> locfit 1.5-9.7 2023-01-02
set.seed(7)
fit <- locfit(~rnorm(n = 1000))
plot(fit)
set.seed(7)
xvalues <- seq(min(rnorm(n = 1000)), max(rnorm(n = 1000)), length.out = 100)
pred <- predict(fit, xvalues)
plot(1, type="n", xlab="", ylab="", xlim=c(-3, 3), ylim=c(0, 0.4))
lines(xvalues, pred, lwd = 10)
Created on 2023-02-09 with reprex v2.0.2
Upvotes: 2
Reputation: 21937
There is not currently a way to do that in the existing function. When you call plot()
on the locfit
object, it calls preplot.locift()
on your object, and then plot.preplot.locfit()
which calls plot.locfit.1d()
. The relevant lines from the code are:
plot(xev[ord], yy[ord], type = "n", xlab = xlab, ylab = ylab,
main = main, xlim = range(x$xev[[1]]), ylim = ylim,
...)
}
lines(xev[ord], yy[ord], type = type, lty = lty, col = col)
As you can see, the ...
goes through to the plot
function, but the line actually gets added with lines()
which does not have access to other arguments specified in ...
Upvotes: 2