scatterplot | R Documentation |
Creates a scatter plot and calculates a correlation between two variables.
scatterplot( data = NULL, x_var_name = NULL, y_var_name = NULL, dot_label_var_name = NULL, weight_var_name = NULL, alpha = 1, annotate_stats = TRUE, annotate_y_pos = 5, annotated_stats_color = "green4", annotated_stats_font_size = 6, annotated_stats_font_face = "bold", line_of_fit_type = "lm", ci_for_line_of_fit = FALSE, line_of_fit_color = "blue", line_of_fit_thickness = 1, dot_color = "black", x_axis_label = NULL, y_axis_label = NULL, dot_size = 2, dot_label_size = NULL, dot_size_range = c(3, 12), jitter_x_percent = 0, jitter_y_percent = 0, cap_axis_lines = FALSE, color_dots_by = NULL )
data |
a data object (a data frame or a data.table) |
x_var_name |
name of the variable that will go on the x axis |
y_var_name |
name of the variable that will go on the y axis |
dot_label_var_name |
name of the variable that will be used to label individual observations |
weight_var_name |
name of the variable by which to weight the individual observations for calculating correlation and plotting the line of fit |
alpha |
opacity of the dots (0 = completely transparent, 1 = completely opaque) |
annotate_stats |
if |
annotate_y_pos |
position of the annotated stats, expressed
as a percentage of the range of y values by which the annotated
stats will be placed above the maximum value of y in the data set
(default = 5). If |
annotated_stats_color |
color of the annotated stats (default = "green4"). |
annotated_stats_font_size |
font size of the annotated stats (default = 6). |
annotated_stats_font_face |
font face of the annotated stats (default = "bold"). |
line_of_fit_type |
if |
ci_for_line_of_fit |
if |
line_of_fit_color |
color of the line of fit (default = "blue") |
line_of_fit_thickness |
thickness of the line of fit (default = 1) |
dot_color |
color of the dots (default = "black") |
x_axis_label |
alternative label for the x axis |
y_axis_label |
alternative label for the y axis |
dot_size |
size of the dots on the plot (default = 2) |
dot_label_size |
size for dots' labels on the plot. If no
input is entered for this argument, it will be set as
|
dot_size_range |
minimum and maximum size for dots on the plot when they are weighted |
jitter_x_percent |
horizontally jitter dots by a percentage of the range of x values |
jitter_y_percent |
vertically jitter dots by a percentage of the range of y values |
cap_axis_lines |
logical. Should the axis lines be capped at the outer tick marks? (default = TRUE) |
color_dots_by |
name of the variable that will determine colors of the dots |
If a weighted correlation is to be calculated, the following package(s) must be installed prior to running the function: Package 'weights' v1.0 (or possibly a higher version) by John Pasek (2018), https://cran.r-project.org/package=weights
the output will be a scatter plot, a ggplot object.
## Not run: scatterplot(data = mtcars, x_var_name = "wt", y_var_name = "mpg") scatterplot( data = mtcars, x_var_name = "wt", y_var_name = "mpg", dot_label_var_name = "hp", weight_var_name = "drat", annotate_stats = TRUE) scatterplot( data = mtcars, x_var_name = "wt", y_var_name = "mpg", dot_label_var_name = "hp", weight_var_name = "cyl", dot_label_size = 7, annotate_stats = TRUE) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.