plot_scatter {COINr} | R Documentation |
Scatter plot of two variables
Description
This is a convenient quick scatter plot function for plotting any two variables x and y in a coin against each other.
At a minimum, you must specify the data set and iCode of both x and y using the dsets
and iCodes
arguments.
Usage
plot_scatter(
coin,
dsets,
iCodes,
...,
by_group = NULL,
alpha = 0.5,
axes_label = "iCode",
dset_label = TRUE,
point_label = NULL,
check_overlap = TRUE,
nudge_y = 5,
log_scale = c(FALSE, FALSE)
)
Arguments
coin |
A coin object |
dsets |
A 2-length character vector specifying the data sets to extract v1 and v2 from,
respectively (passed as |
iCodes |
A 2-length character vector specifying the |
... |
Optional further arguments to be passed to |
by_group |
A string specifying an optional group variable. If specified, the plot will be coloured by this grouping variable. |
alpha |
Transparency value for points between 0 and 1, passed to ggplot2. |
axes_label |
A string specifying how to label axes and legend. Either |
dset_label |
Logical: if |
point_label |
Specifies whether and how to label points. If |
check_overlap |
Logical: if |
nudge_y |
Parameter passed to ggplot which controls the vertical adjustment of the text labels if present. |
log_scale |
A 2-length logical vector specifying whether to use log axes for x and y respectively: if |
Details
Optionally, the scatter plot can be coloured by grouping variables specified in the coin (see by_group
). Points
and axes can be labelled using other arguments.
This function is powered by ggplot2 and outputs a ggplot2 object. To further customise the plot, assign the output
of this function to a variable and use ggplot2 commands to further edit. See vignette("visualisation
) for more details on plotting.
Value
A ggplot2 object.
Examples
# build example coin
coin <- build_example_coin(up_to = "new_coin")
# scatter plot of Flights against Population
# coloured by GDP per capita
# log scale applied to population
plot_scatter(coin, dsets = c("uMeta", "Raw"),
iCodes = c("Population", "Flights"),
by_group = "GDPpc_group", log_scale = c(TRUE, FALSE))