certara / ggcertara

A ggplot2 theme for Certara CSC-iDD
4 stars 2 forks source link

Smoother Function Issue #22

Closed DuyTran16 closed 2 years ago

DuyTran16 commented 2 years ago

I am looking at the vignette on website. On "Basic usage" section with output plot from gof(dat), the smoother line in red color for dv_vs_pred (DV vs. PRED) doesn't look correct as the smooth function shows perfect unison to the identity black, dashed line but there are some observed points above the identity line.

Is it possible to remove this default smoother line and customize smoothing line shown below: gof(dat) & geom_smooth(method="lm")

benjaminrich commented 2 years ago

Hi @DuyTran16,

You could, but I don't recommend it. If you really want to do this, you can override the default baseplot function, like this:

mybaseplot <- function(data, ...) {
  ggplot(data) + geom_point_c() + theme(aspect.ratio=1)
}

gof(dat, baseplot=mybaseplot) & geom_smooth(method="lm")

You could even embed the new geom_smooth into your baseplot function, like this:

mybaseplot2 <- function(data, ...) {
  ggplot(data) + geom_point_c() + theme(aspect.ratio=1) + geom_smooth(method="lm")
}

gof(dat, baseplot=mybaseplot2)

A better option might be to change the LOESS parameters, (e.g. span, degree, and family; see ?loess.smooth for details), which you can do like this (Note: this is for illustration only, I'm not at all suggesting you use these values):

gof(dat, loess.args=list(span=0.5, degree=2))

That may allow you to change the appearance of the LOESS smooth to something you feel captures the overall trend better - the problem is that it is quite subjective, and you should be careful not to mask any indication that the model fit isn't adequate.

DuyTran16 commented 2 years ago

There is something odd with the default settings for dv_vs_pred() function as the LOESS line is giving almost unison to identity line when these lines shouldn't match. thank you @benjaminrich for your advice to solving the smoothing line.