View source: R/plot_xy_Group.R
plot_xy_Group | R Documentation |
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,
...
)
data |
A data frame containing the variables to be plotted. |
xcol |
A column name in |
ycol |
A column name in |
Group |
A grouping variable used for colour/fill aesthetics. Whether this variable is numeric or not will determine colour palette choice for the |
facet |
An optional variable for faceting the plot using |
ErrorType |
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 |
SmoothType |
Add a smoothened average using 'Loess' or 'Linear', which will be passed on to |
symsize |
Size of the raw data points. Default is |
s_alpha |
Alpha transparency for raw data points. Default is |
TextXAngle |
Angle of x-axis text labels. Default is |
mean_size |
Size of the square symbol representing the mean. Default is |
m_alpha |
Alpha transparency for the mean symbol. Default is |
LogYTrans |
transform Y axis into "log10" or "log2" (in quotes). |
LogXTrans |
transform X axis into "log10" or "log2" |
LogYBreaks |
argument for |
LogXBreaks |
argument for |
LogYLabels |
argument for |
LogXLabels |
argument for |
LogYLimits |
a vector of length two specifying the range (minimum and maximum) of the Y axis. |
LogXLimits |
a vector of length two specifying the range (minimum and maximum) of the X axis. |
facet_scales |
whether or not to fix scales on X & Y axes for all graphs. Can be |
fontsize |
parameter of |
bwid |
width of boxplot (default = 0.3). |
b_alpha |
fractional opacity of boxes (default = 0.3). |
l_alpha |
fractional opacity of lines joining boxes, (default = 0.8). |
sm_alpha |
fractional opacity of error range around loess or linear smooth fit (default = 0.3). |
symthick |
size (in 'pt' units) of outline of symbol lines ( |
bthick |
size (in 'pt' units) of outline of boxes, whisker and joining lines ( |
ewid |
width of errorbars (default = 0.1). |
e_alpha |
fractional opacity of error bars (default = 1). |
ColPal |
Character. Name of the colour palette to use from grafify. For categorical variables, one of: |
ColSeq |
logical TRUE or FALSE. Default TRUE for sequential colours from chosen palette. Set to FALSE for distant colours, which will be applied using |
ColRev |
whether to reverse order of colour within the selected palette, default F (FALSE); can be set to T (TRUE). |
... |
Additional arguments passed to |
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
.
This function returns a ggplot2
object of class "gg" and "ggplot".
#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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.