[R] back-transform predictors for x-axis in plot -- mgcv package

hadley wickham h.wickham at gmail.com
Fri Jun 15 12:33:03 CEST 2007


Hi Suzan,

You can do sort of backtransformation inside of ggplot2
(http://had.co.nz/ggplot2).

library(ggplot2)

# Create the base scatterplot with y and x axes transformed by logging,
# and then back transformed by exponentiating
(base <- qplot(carat, price, data=diamonds) + scale_x_log10() +
scale_y_log10() + coord_trans(y="pow10", x="pow10"))

base + geom_smooth(method="lm")

library(mgcv)
base + geom_smooth(method="gam", formula = y ~ s(x, bs="cr"))
base + geom_smooth(method="gam", formula = y ~ s(x, bs="cr"), fill="grey50")

# cf.

qplot(carat, price, data=diamonds) + geom_smooth(method="lm")
qplot(carat, price, data=diamonds) + geom_smooth(method="gam", formula
= y ~ s(x, bs="cr"), fill="grey50")


Regards,

Hadley

On 6/14/07, Suzan Pool <Suzan.Pool at noaa.gov> wrote:
> My question is related to plot( ) in the mgcv package.  Before modelling
> the data, a few predictors were transformed to normalize them.
> Therefore, the x-axes in the plots show transformed predictor values.
> How do I back-transform the predictors so that the plots are easier to
> interpret?
>
> Thanks in advance,
> Suzan
>
> --
> Suzan Pool
> Oregon State University
> Cooperative Institute for Marine Resources Studies
> c/o NOAA Fisheries
> 520 Heceta Place
> P.O. Box 155
> Hammond, OR  97121
>
> Suzan.Pool at oregonstate.edu
> Suzan.Pool at noaa.gov
> Phone:  503-861-1818 x36 TTY
> Voice to TTY:  711
> Fax:  503-861-2589
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list