# Make the basic plot
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg"
)
# \donttest{
.old_wd <- setwd(tempdir())
# Save a high-resolution image file to specified directory
ggplot2::ggsave("nicescatterplothere.pdf", width = 7,
height = 7, unit = "in", dpi = 300
) # change for your own desired path
setwd(.old_wd)
# Change x- and y- axis labels
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
ytitle = "Miles/(US) gallon",
xtitle = "Weight (1000 lbs)"
)
# Have points "jittered", loess method
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
has.jitter = TRUE,
method = "loess"
)
# Change the transparency of the points
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
alpha = 1
)
# Remove points
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
has.points = FALSE,
has.jitter = FALSE
)
# Add confidence band
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
has.confband = TRUE
)
# Set x- and y- scales manually
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
xmin = 1,
xmax = 6,
xby = 1,
ymin = 10,
ymax = 35,
yby = 5
)
# Change plot colour
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
colours = "blueviolet"
)
# Add correlation coefficient to plot and p-value
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
has.r = TRUE,
has.p = TRUE
)
# Change location of correlation coefficient or p-value
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
has.r = TRUE,
r.x = 4,
r.y = 25,
has.p = TRUE,
p.x = 5,
p.y = 20
)
# Plot by group
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
group = "cyl"
)
# Use full range on the slope/confidence band
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
group = "cyl",
has.fullrange = TRUE
)
# Remove lines
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
group = "cyl",
has.line = FALSE
)
# Change order of labels on the legend
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
group = "cyl",
groups.order = c(8, 4, 6)
)
# Change legend labels
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
group = "cyl",
groups.labels = c("Weak", "Average", "Powerful")
)
# Warning: This applies after changing order of level
# Add a title to legend
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
group = "cyl",
legend.title = "cylinders"
)
# Plot by group + manually specify colours
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
group = "cyl",
colours = c("burlywood", "darkgoldenrod", "chocolate")
)
# Plot by group + use different line types for each group
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
group = "cyl",
has.linetype = TRUE
)
# Plot by group + use different point shapes for each group
nice_scatter(
data = mtcars,
predictor = "wt",
response = "mpg",
group = "cyl",
has.shape = TRUE
)
# }
Run the code above in your browser using DataLab