Learn R Programming

r2spss (version 0.3.2)

scatter_plot: Scatter Plot and Scatter Plot Matrix

Description

Draw a scatter plot or a scatter plot matrix of variables in a data frame. The plots thereby mimic the look of SPSS graphs.

Usage

scatter_plot(data, variables, version = r2spss_options$get("version"), ...)

Arguments

data

a data frame containing the variables to be plotted.

variables

a character vector specifying at least two variables to be plotted. In case of two variables, a simple scatter plot is produced with the first variable on the \(x\)-axis and the second variable on the \(y\)-axis. In case of more than two variables, a scatter plot matrix is produced.

version

a character string specifying whether the plot should mimic the look of recent SPSS versions ("modern") or older versions (<24; "legacy").

for a simple scatter plot, additional arguments are passed down to geom_point. For a scatter plot matrix, additional arguments to be passed down, in particular base graphics parameters (see par).

Value

In case of a simple scatter plot, an object of class "ggplot", which produces the plot when printed.

In case of a scatter plot matrix, nothing is returned but a plot is produced.

Examples

Run this code
# NOT RUN {
# load data
data("Eredivisie")
# log-transform market values
Eredivisie$logMarketValue <- log(Eredivisie$MarketValue)

# plot log market values against age
scatter_plot(Eredivisie, c("Age", "logMarketValue"))

# scatterplot matrix of age, number of minutes played, and
# log market values
scatter_plot(Eredivisie, c("Age", "Minutes", "logMarketValue"))

# }

Run the code above in your browser using DataLab