# NOT RUN {
# load sample date
library(sjmisc)
library(sjlabelled)
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