GG_scatter | R Documentation |
Plots a scatterplot with a regression line and correlation information. Returns a ggplot2
object.
GG_scatter(
df,
x_var,
y_var,
weights = NULL,
color = NULL,
se = T,
alpha = 1,
text_pos = NA,
case_names = NULL,
case_names_color = "black",
CI = 0.95,
clean_names = T,
check_overlap = T,
repel_names = F,
weight_as_size = T,
...
)
df |
(data.frame) A data frame with variables. |
x_var |
(chr scalar) X variable string. |
y_var |
(chr scalar) Y variable string. |
weights |
(num scalar) A set of weights to use. |
color |
(chr) A variable to color points by. |
alpha |
(num) The alpha to use. |
text_pos |
(chr scalar) Where to put the text. Defaults to top left ("tl") if correlation is positive, or tr if negative. Can be tl, tr, bl, or br. |
case_names |
(lgl scalar) Whether to add case names or not (default true). |
case_names_color |
(lgl scalar) Color of case names. |
CI |
(num scalar) Confidence interval as a fraction. |
clean_names |
(lgl scalar) Whether to clean the axes names using |
check_overlap |
(lgl scalar) Whether to avoid overplotting names. |
repel_names |
(lgl) If using case names, should they be repelled? |
weight_as_size |
(lgl scalar) Whether to resize points by the weights. |
... |
Internally uses the ad hoc variables .weights
, .label
and .color
. If you name your variables these, then you will get odd problems.
GG_scatter(iris, "Sepal.Length", "Sepal.Width") #default plot
GG_scatter(iris, "Sepal.Length", "Sepal.Width", se = F) #no SE ribbon
GG_scatter(iris, "Sepal.Length", "Sepal.Width", case_names = rep("A", 150)) #case names
GG_scatter(iris, "Sepal.Length", "Sepal.Width", case_names = "Species") #case names from variable
GG_scatter(iris, "Sepal.Length", "Sepal.Width", case_names = "Species", case_names_color = "purple") #case names in purple
GG_scatter(iris, "Sepal.Length", "Sepal.Width", case_names = "Species", repel_names = T) #case names from variable, repelled
GG_scatter(iris, "Sepal.Length", "Sepal.Width", text_pos = "br") #other text location
GG_scatter(iris, "Sepal.Length", "Sepal.Width", CI = .99) #other CI
GG_scatter(iris, "Sepal.Length", "Sepal.Width", clean_names = F) #don't clean names
GG_scatter(iris, "Sepal.Length", "Sepal.Width", weights = 1:150) #add weights with vector
GG_scatter(iris, "Sepal.Length", "Sepal.Width", weights = "Petal.Width") #add weights with name
GG_scatter(iris, "Sepal.Length", "Sepal.Width", weights = 1:150, weight_as_size = F) #add weights with vector but don't resize
GG_scatter(iris, "Sepal.Length", "Sepal.Width", color = "Species") #color points
GG_scatter(iris, "Sepal.Length", "Sepal.Width", color = "Species", case_names = "Species") #color points, but labels stay black
GG_scatter(iris, "Sepal.Length", "Sepal.Width", alpha = .1) #change alpha
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.