plot_scatter.Rd
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.
plot_scatter(data, x, y, grp, title = "", legend.title = NULL, legend.labels = NULL, dot.labels = NULL, axis.titles = NULL, dot.size = 1.5, label.size = 3, colors = "metro ui", fit.line = NULL, fit.grps = NULL, show.rug = FALSE, show.legend = TRUE, show.ci = FALSE, wrap.title = 50, wrap.legend.title = 20, wrap.legend.labels = 20, jitter = 0.05, emph.dots = FALSE, grid = FALSE)
data | A data frame, or a grouped data frame. |
---|---|
x | Name of the variable for the x-axis. |
y | Name of the variable for the y-axis. |
grp | Optional, name of the grouping-variable. If not missing, the scatter plot will be grouped. See 'Examples'. |
title | Character vector, used as plot title. By default,
|
legend.title | Character vector, used as legend title for plots that have a legend. |
legend.labels | character vector with labels for the guide/legend. |
dot.labels | Character vector with names for each coordinate pair given
by |
axis.titles | character vector of length one or two, defining the title(s) for the x-axis and y-axis. |
dot.size | Numeric, size of the dots that indicate the point estimates. |
label.size | Size of text labels if argument |
colors | May be a character vector of color values in hex-format, valid
color value names (see
|
fit.line, fit.grps | Specifies the method to add a fitted line accross
the data points. Possible values are for instance |
show.rug | Logical, if |
show.legend | For Marginal Effects plots, shows or hides the legend. |
show.ci | Logical, if |
wrap.title | Numeric, determines how many chars of the plot title are displayed in one line and when a line break is inserted. |
wrap.legend.title | numeric, determines how many chars of the legend's title are displayed in one line and when a line break is inserted. |
wrap.legend.labels | numeric, determines how many chars of the legend labels are displayed in one line and when a line break is inserted. |
jitter | Numeric, between 0 and 1. If |
emph.dots | Logical, if |
grid | Logical, if |
A ggplot-object. For grouped data frames, a list of ggplot-objects for each group in the data.
# load sample date library(sjmisc) library(sjlabelled) data(efc) # simple scatter plot plot_scatter(efc, e16sex, neg_c_7)# simple scatter plot, increased jittering plot_scatter(efc, e16sex, neg_c_7, jitter = .4)# grouped scatter plot plot_scatter(efc, c160age, e17age, e42dep)# grouped scatter plot with marginal rug plot # and add fitted line for complete data plot_scatter( efc, c12hour, c160age, c172code, show.rug = TRUE, fit.line = "lm" )# grouped scatter plot with marginal rug plot # and add fitted line for each group plot_scatter( efc, c12hour, c160age, c172code, show.rug = TRUE, fit.grps = "loess", grid = TRUE )