Search code examples
rloessancova

How to change the axis and legend on loess.ancova function


I am trying to do an ANCOVA test of a specific dataset using fANCOVA package and the loess.ancova function.

loess.ancova(y=dt$response,x=dt$var1,group=dt$species,family= "gaussian",method="Speckman", plot = T)

After calling the code I get a plot similar to thisenter image description here

How can I change the legend and the axis names? I tried using

loess.ancova(y,x,group,...,plot=T, xlab="var1", ylab="response")

but nothing changed, since that failed I have no idea how to even try to change the legend

Any help would be appreciated


Solution

  • one possibility is to save the result of your loess.ancova call:

    result <- loess.ancova(y=dt$response,
                           x=dt$var1,
                           group=dt$species,
                           family= "gaussian",
                           method="Speckman",
                           plot = T
                           )
    

    Inspection of the result with str(result) shows that it contains an item "smooth.fit":

    > str(result)
    List of 2
     $ linear.fit: num [1:3, 1] 5.88 -3.01 -6.1
      ..- attr(*, "dimnames")=List of 2
      .. ..$ : chr [1:3] "(Intercept)" "group2" "group3"
      .. ..$ : NULL
     $ smooth.fit:List of 18
      ..$ n        : int 245
      ..$ fitted   : num [1:245
    ## [truncated]
    

    ... which you can plot, using the desired base plot() arguments:

    result$smooth.fit |> plot(xlab = 'my x-axis label', ...)