Learn R Programming

sjPlot (version 2.0.0)

sjp.scatter: Plot (grouped) scatter plots

Description

Display scatter plot of two variables. Adding a grouping variable to the scatter plot is possible. Furthermore, fitted lines can be added for each group as well as for the overall plot.

Usage

sjp.scatter(x = NULL, y = NULL, grp = NULL, title = "",
  legend.title = NULL, legend.labels = NULL, dot.labels = NULL,
  axis.titles = NULL, wrap.title = 50, wrap.legend.title = 20,
  wrap.legend.labels = 20, geom.size = 2, label.size = 3,
  geom.colors = NULL, show.axis.values = TRUE, fit.line.grps = FALSE,
  fit.line = FALSE, show.ci = FALSE, fitmethod = "lm",
  jitter.dots = FALSE, emph.dots = FALSE, auto.jitter = TRUE,
  jitter.ratio = 0.15, show.rug = FALSE, show.legend = TRUE,
  facet.grid = FALSE, prnt.plot = TRUE)

Arguments

Value

(Insisibily) returns the ggplot-object with the complete plot (plot) as well as the data frame that was used for setting up the ggplot-object (df).

See Also

http://www.strengejacke.de/sjPlot/sjp.scatter{sjPlot manual: sjp.scatter}

Examples

Run this code
# load sample date
library(sjmisc)
data(efc)

# simple scatter plot, auto-jittering
sjp.scatter(efc$e16sex, efc$neg_c_7)

# simple scatter plot, no jittering needed
sjp.scatter(efc$c160age, efc$e17age)

# grouped scatter plot
sjp.scatter(efc$c160age, efc$e17age, efc$e42dep)

# grouped and jittered scatter plot with marginal rug plot
sjp.scatter(efc$e16sex,efc$neg_c_7, efc$c172code, show.rug = TRUE)

# grouped and labelled scatter plot, not using the auto-detection
# of labels, but instead pass labels as arguments
sjp.scatter(efc$c160age, efc$e17age, efc$e42dep,
            title = "Scatter Plot", legend.title = get_label(efc)['e42dep'],
            legend.labels = get_labels(efc)[['e42dep']],
            axis.titles = c(get_label(efc)['c160age'], get_label(efc)['e17age']),
            fit.line.grps = TRUE)

# grouped and labelled scatter plot as facets
sjp.scatter(efc$c160age,efc$e17age, efc$e42dep, fit.line.grps = TRUE,
            facet.grid = TRUE, show.ci = TRUE)

# plot residuals of fitted models
fit <- lm(neg_c_7 ~ quol_5, data = efc)
sjp.scatter(y = fit$residuals, fit.line = TRUE)

# "hide" axis titles
sjp.scatter(efc$c160age, efc$e17age, efc$e42dep, title = "", 
            axis.titles = c("", ""))

# plot text labels
pl <- c(1:10)
for (i in 1:10) 
  pl[i] <- paste(sample(c(0:9, letters, LETTERS), 8, replace = TRUE), collapse = "")
sjp.scatter(runif(10), runif(10), dot.labels = pl)

Run the code above in your browser using DataLab