View source: R/stat_plotlm_v3.R View source: R/stat_plotlm_v2.R View source: R/stat_plotlm.R
stat_plotlm | R Documentation |
This is a replacement for stat_smooth
where you can supply your own model fit (lm or lmer)
to be plotted as a trend line.
This is a replacement for stat_smooth
where you can supply your own model fit (lm or lmer)
to be plotted as a trend line.
This is a replacement for stat_smooth
where you can supply your own model fit (lm or lmer)
to be plotted as a trend line.
stat_plotlm( mapping = NULL, data = NULL, geom = "smooth", position = "identity", show.legend = NA, inherit.aes = TRUE, fitted_model = NULL, se = TRUE, fullrange = FALSE, n = 100, SEs = 2, fulldata = NULL, ... ) stat_plotlm( mapping = NULL, data = NULL, geom = "smooth", position = "identity", show.legend = NA, inherit.aes = TRUE, fitted_model = NULL, se = TRUE, fullrange = FALSE, n = 100, SEs = 2, fulldata = NULL, ... ) stat_plotlm( mapping = NULL, data = NULL, geom = "smooth", position = "identity", show.legend = NA, inherit.aes = TRUE, fitted_model = NULL, se = TRUE, fullrange = FALSE, n = 100, SEs = 2, fulldata = NULL, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
Use to override the default connection between
|
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
fitted_model |
a model object (ex from lm or lmer) compatible with the 'predict' function |
se |
display confidence interval around smooth? (TRUE by default, see level to control) |
fullrange |
Should the fit span the full range of the plot, or just the data? |
n |
Number of points at which to evaluate smoother. |
SEs |
width of confidence interval band (in se's) |
... |
Other arguments passed on to |
The main difference from stat_smooth, or other geom_ of stat_ functions is that you must add
all of the terms in the model as Aesthetics in the aes() argument, naming them the same as in your
data: aes(Group1 = Group1, Group2 = Group2, Covariate = Covariate)
The main difference from stat_smooth, or other geom_ of stat_ functions is that you must add
all of the terms in the model as Aesthetics in the aes() argument, naming them the same as in your
data: aes(Group1 = Group1, Group2 = Group2, Covariate = Covariate)
The main difference from stat_smooth, or other geom_ of stat_ functions is that you must add
all of the terms in the model as Aesthetics in the aes() argument, naming them the same as in your
data: aes(Group1 = Group1, Group2 = Group2, Covariate = Covariate)
library(ggplot2) lm_mpg = lm(hwy ~ displ,mpg) ggplot(mpg,aes(x=displ,y=hwy)) + geom_point() + stat_plotlm(fitted_model = lm_mpg,aes(displ = displ),se=T) # add faceting lm_drv = lm(hwy ~ poly(displ,2)*drv,mpg) ggplot(mpg,aes(x=displ,y=hwy)) + geom_point() + facet_wrap(~drv,scales = 'free') + stat_plotlm(fitted_model = lm_drv,aes(displ = displ,drv=drv),se=T,fullrange=T,n=20) # add multiple colors in each facet. Note that the group aesthetic is necessary for stat_plotlm lm_trans = lm(hwy ~ poly(displ,2)*drv + trans,mpg) ggplot(mpg,aes(x=displ,y=hwy)) + geom_point(aes(color = drv)) + facet_wrap(~trans,scales = 'free') + stat_plotlm(fitted_model = lm_trans, aes(group = drv,color = drv,displ = displ,drv=drv,trans=trans), se=T,fullrange=T,n=20) library(ggplot2) lm_mpg = lm(hwy ~ displ,mpg) ggplot(mpg,aes(x=displ,y=hwy)) + geom_point() + stat_plotlm(fitted_model = lm_mpg,aes(displ = displ),se=T) # add faceting lm_drv = lm(hwy ~ poly(displ,2)*drv,mpg) ggplot(mpg,aes(x=displ,y=hwy)) + geom_point() + facet_wrap(~drv,scales = 'free') + stat_plotlm(fitted_model = lm_drv,aes(displ = displ,drv=drv),se=T,fullrange=T,n=20) # add multiple colors in each facet. Note that the group aesthetic is necessary for stat_plotlm lm_trans = lm(hwy ~ poly(displ,2)*drv + trans,mpg) ggplot(mpg,aes(x=displ,y=hwy)) + geom_point(aes(color = drv)) + facet_wrap(~trans,scales = 'free') + stat_plotlm(fitted_model = lm_trans, aes(group = drv,color = drv,displ = displ,drv=drv,trans=trans), se=T,fullrange=T,n=20) library(ggplot2) lm_mpg = lm(hwy ~ displ,mpg) ggplot(mpg,aes(x=displ,y=hwy)) + geom_point() + stat_plotlm(fitted_model = lm_mpg,aes(displ = displ),se=T) # add faceting lm_drv = lm(hwy ~ poly(displ,2)*drv,mpg) ggplot(mpg,aes(x=displ,y=hwy)) + geom_point() + facet_wrap(~drv,scales = 'free') + stat_plotlm(fitted_model = lm_drv,aes(displ = displ,drv=drv),se=T,fullrange=T,n=20) # add multiple colors in each facet. Note that the group aesthetic is necessary for stat_plotlm lm_trans = lm(hwy ~ poly(displ,2)*drv + trans,mpg) ggplot(mpg,aes(x=displ,y=hwy)) + geom_point(aes(color = drv)) + facet_wrap(~trans,scales = 'free') + stat_plotlm(fitted_model = lm_trans, aes(group = drv,color = drv,displ = displ,drv=drv,trans=trans), se=T,fullrange=T,n=20)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.