This function takes a data table, quantitative X and Y variables along with a grouping variable that is either categorical or numeric. The colour of data symbols is mapped to the grouping variable. This function is related to plot_xy_CatGroup
and plot_xy_NumGroup
, and could eventually replace them in future updates.
Central value and scatter can be shown by choosing the ErrorType
argument. Mean and error bars (SD, SEM or CI95) or box and whisker plot options are available.
plot_xy_Group(
data,
xcol,
ycol,
Group,
facet,
ErrorType = c("none", "SD", "SEM", "CI95", "Boxplot"),
SmoothType = c("none", "Loess", "Linear"),
symsize = 3,
s_alpha,
TextXAngle = 0,
mean_size,
m_alpha = 1,
LogYTrans,
LogXTrans,
LogYBreaks = waiver(),
LogXBreaks = waiver(),
LogYLabels = waiver(),
LogXLabels = waiver(),
LogYLimits = NULL,
LogXLimits = NULL,
facet_scales = "fixed",
fontsize = 20,
bwid = 0.3,
b_alpha = 0.3,
l_alpha = 0.8,
sm_alpha = 0.3,
symthick,
bthick,
ewid = 0.1,
e_alpha = 1,
ColPal = NULL,
ColSeq = TRUE,
ColRev = FALSE,
...
)
This function returns a ggplot2
object of class "gg" and "ggplot".
A data frame containing the variables to be plotted.
A column name in data
for the x-axis (typically a factor or grouping variable).
A column name in data
for the y-axis (numeric).
A grouping variable used for colour/fill aesthetics. Whether this variable is numeric or not will determine colour palette choice for the ColPal
argument.
An optional variable for faceting the plot using facet_wrap()
.
select the way to show data centrality and dispersion. The default is "none", which can be changed to "SD" (standard deviation), "SEM" (standard error of the mean) or "CI95" (95% confidence interval based on t distributions); all these will be displayed with a square symbol representing the mean. Choosing Boxplot
will show a box and whiskers plot and the median. A line joining the central values will also appear. Use l_alpha = 0
to not show the line.
Add a smoothened average using 'Loess' or 'Linear', which will be passed on to stat_smooth
as method = "loess"
or method = "lm"
, respectively.
Size of the raw data points. Default is 3
.
Alpha transparency for raw data points. Default is 0.8
, which will reduce to 0.2
when an ErrorType
is set.
Angle of x-axis text labels. Default is 0
.
Size of the square symbol representing the mean. Default is symsize + 3
to prominently show the central value.
Alpha transparency for the mean symbol. Default is 1
.
transform Y axis into "log10" or "log2" (in quotes).
transform X axis into "log10" or "log2"
argument for ggplot2[scale_y_continuous]
for Y axis breaks on log scales, default is waiver()
, or provide a vector of desired breaks.
argument for ggplot2[scale_x_continuous]
for Y axis breaks on log scales, default is waiver()
, or provide a vector of desired breaks.
argument for ggplot2[scale_y_continuous]
for Y axis labels on log scales, default is waiver()
, or provide a vector of desired labels.
argument for ggplot2[scale_x_continuous]
for Y axis labels on log scales, default is waiver()
, or provide a vector of desired labels.
a vector of length two specifying the range (minimum and maximum) of the Y axis.
a vector of length two specifying the range (minimum and maximum) of the X axis.
whether or not to fix scales on X & Y axes for all graphs. Can be fixed
(default), free
, free_y
or free_x
(for Y and X axis one at a time, respectively).
parameter of base_size
of fonts in theme_classic
, default set to size 20.
width of boxplot (default = 0.3).
fractional opacity of boxes (default = 0.3).
fractional opacity of lines joining boxes, (default = 0.8).
fractional opacity of error range around loess or linear smooth fit (default = 0.3).
size (in 'pt' units) of outline of symbol lines (stroke
), default = fontsize
/22.
size (in 'pt' units) of outline of boxes, whisker and joining lines (stroke
), default = fontsize
/22.
width of errorbars (default = 0.1).
fractional opacity of error bars (default = 1).
Character. Name of the colour palette to use from grafify. For categorical variables, one of: "okabe_ito"
, "all_grafify"
, "bright"
, "contrast"
, "dark"
, "fishy"
, "kelly"
, "light"
, "muted"
, "pale"
, "r4"
, "safe"
, "vibrant"
. For quantitative variables, one of: blue_conti
, yellow_conti
, grey_conti
, PrGn_div
, PrGn_div
.
logical TRUE or FALSE. Default TRUE for sequential colours from chosen palette. Set to FALSE for distant colours, which will be applied using scale_fill_grafify2
.
whether to reverse order of colour within the selected palette, default F (FALSE); can be set to T (TRUE).
Additional arguments passed to ggplot2
geoms or scales.
When ErrorType
is set to a value other than none
, a line joining the central value (mean or median, respectively) will also appear (set l_alpha = 0
if this is not desired). Other options for ErrorType
are: SD
, SEM
, CI95
, Boxplot
.
When SD
/SEM
/CI95
are chosen, the mean value will appear as a larger square symbol. Its opacity and size can be adjusted with m_alpha
and mean_size
, respectively.
The smooth fitted line type can be shown with the SmoothType
argument, which can take the following options: none
, Linear
or Loess
. Latter two options are fitted using stat_smooth
with lm
or loess
options, respectively.
Colours can be changed using ColPal
, ColRev
or ColSeq
arguments. Colours available can be seen quickly with plot_grafify_palette
.
ColPal
can be one of the following: "okabe_ito", "dark", "light", "bright", "pale", "vibrant, "muted" or "contrast".
ColRev
(logical TRUE/FALSE) decides whether colours are chosen from first-to-last or last-to-first from within the chosen palette.
ColSeq
(logical TRUE/FALSE) decides whether colours are picked by respecting the order in the palette or the most distant ones using colorRampPalette
.
#The grouping factor cyl is automatically converted to categorical variable
plot_xy_Group(data = mpg,
xcol = cyl, ycol = cty, Group = drv,
ErrorType = "SD")
#with a Linear smooth line
plot_xy_Group(data = mpg,
xcol = cyl, ycol = cty, Group = drv,
ErrorType = "SD", SmoothType = "Linear")
Run the code above in your browser using DataLab