Contenuto principale

variabilitychart

R2026b

Variability chart

Since R2026b

    Description

    variabilitychart(factors,ydata) creates a variability chart for ydata based on the grouping variables in factors.

    example

    variabilitychart(tbl,yvar) creates a variability chart for the variable yvar in the table tbl using the remaining table variables as grouping variables.

    example

    variabilitychart(___,Name=Value) specifies additional options using one or more name-value arguments. For example, you can specify the names of the factors or add boxes around the level data for specific factors.

    example

    variabilitychart(parent,___) creates the variability chart in the specified parent container.

    example

    v = variabilitychart(___) returns a VariabilityChart object. Use v to set properties of the variability chart after creating it. For a list of properties, see VariabilityChart Properties.

    example

    Examples

    collapse all

    This example shows how to create a variability chart from categorical factor vectors and a numeric response vector to identify sources of variation in a manufacturing process.

    Define data for a component manufacturing process with three operators and two machines. Each operator uses each machine four times.

    operator = repelem(categorical(["Op1","Op2","Op3"]),8)';
    machine = repmat(categorical(["M1","M2"]),1,12)';

    Simulate part thickness measurements with variation due to operator and machine differences.

    rng(0) % For reproducibility
    thickness = 5 + 0.3*double(operator) + 0.5*double(machine) + 0.2*randn(24,1);

    Create a variability chart to visualize how thickness varies across operators and machines.

    variabilitychart({operator,machine},thickness)

    Figure contains an object of type variabilitychart.

    Use the variability chart to observe trends in the data. For example, machine M2 seems to produce thicker components than M1. There also appears to be variation based on who is operating the machine.

    This example shows how to create a variability chart by passing a table and specifying the response variable name.

    Construct a table of product weights measured across two production lines, two shifts, and three operators.

    rng(0) % For reproducibility
    Line = repelem(categorical(["Line1","Line2"]),60)';
    Shift = repmat(repelem(categorical(["Day","Night"]),30),1,2)';
    Operator = repmat(repelem(categorical(["Op1","Op2","Op3"]),10),1,4)';
    Weight = 50 + 2*double(Line) + 1.5*double(Shift) + 0.8*randn(120,1);
    tbl = table(Line,Shift,Operator,Weight);

    Create a variability chart for the Weight variable. The function uses the remaining table variables as factors.

    variabilitychart(tbl,"Weight")

    Figure contains an object of type variabilitychart.

    Add boxes around factor levels and a target line to a variability chart using name-value arguments.

    Load the patients data set and store the diastolic blood pressure readings with location and gender factors in a table.

    load patients
    tbl = table(categorical(Location),categorical(Gender),Diastolic, ...
        VariableNames=["Location","Gender","Diastolic"]);

    Create a variability chart with boxes around the first factor and a target line at 80 mmHg representing a clinical threshold.

    variabilitychart(tbl,"Diastolic", ...
        FactorsWithBoxes=1, ...
        TargetValue=80)

    Figure contains an object of type variabilitychart.

    The chart now highlights the grouping structure with boxes around location levels and marks the clinical threshold with a target line at 80 mmHg.

    Create variability charts in specific panel containers within a figure to compare how fuel economy and vehicle weight vary across countries of origin and engine sizes.

    Load the carbig data set and store the origin, cylinder count, fuel economy, and weight data in a table. Filter to the three most-represented countries and remove rows with missing values.

    load carbig
    tbl = table(categorical(cellstr(Origin)),categorical(Cylinders),MPG,Weight, ...
        VariableNames=["Origin","Cylinders","MPG","Weight"]);
    tbl = tbl(ismember(tbl.Origin,["USA","Japan","Germany"]) & ~isnan(tbl.MPG) & ~isnan(tbl.Weight),:);

    Create a figure with two panels, then plot a variability chart in each panel by passing the panel as the first argument.

    f = figure(Position=[100 100 900 400]);
    p1 = uipanel(f,Position=[0 0 0.5 1],Title="MPG");
    variabilitychart(p1,tbl,"MPG",FactorVariables=["Origin","Cylinders"])
    p2 = uipanel(f,Position=[0.5 0 0.5 1],Title="Weight");
    variabilitychart(p2,tbl,"Weight",FactorVariables=["Origin","Cylinders"])

    Figure contains objects of type variabilitychart, uipanel.

    Input Arguments

    collapse all

    Sample data, specified as a numeric vector.

    Data Types: single | double

    Factor variables, specified as a numeric vector, logical vector, categorical vector, string array, cell array of character vectors, or cell array of vectors. Each factor variable must have the same length as ydata.

    Factors are sometimes called grouping variables. The variabilitychart function groups the observations in ydata by their factor values. For more information on factors, see Grouping Variables.

    Data Types: single | double | char | string | cell | categorical

    Source table containing the sample data and factor variables, specified as a table.

    Data Types: table

    Table variable containing the sample data, specified using one of the indexing schemes from the following table.

    Indexing SchemeExamples

    Variable name:

    • A string scalar or character vector.

    • A pattern object. The pattern object must refer to only one variable.

    • "A" or 'A' — A variable named A

    • "Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit

    Variable index:

    • An index number that refers to the location of a variable in the table.

    • A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values.

    • 3 — The third variable from the table

    • [false false true] — The third variable

    Variable type:

    • A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable.

    • vartype("double") — The variable containing double values

    Example: yvar=3

    Parent container, specified as a Figure, Panel, Tab, TiledChartLayout, or GridLayout object.

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: variabilitychart(ydata,factors,TargetValue=5,FactorsWithBoxes=2) uses the data in ydata and the factors in factors to plot a variability chart with boxes around the second factor and a target line at y = 2.

    Note

    The VariabilityChart properties listed here are only a subset. For a complete list, see VariabilityChart Properties.

    Factor names, specified as a string array, cell array of character vectors, or categorical array. FactorNames must have one name for each factor variable.

    The factor names are displayed along the y-axis of the chart in line with each factors' level names. To remove factor names from the chart, specify an empty cell array ({}) for FactorNames.

    If you pass a table to variabilitychart, FactorNames is the names of the table variables by default. If you pass a cell array or vector to variabilitychart, FactorNames is {'Factor1','Factor2',...,'Factorn'}, where n is the number of factors by default.

    Example: FactorNames=["F1","F2","F3"]

    Data Types: char | string | cell | categorical

    Display names of the factor levels, specified as a cell array of vectors. Each cell in LevelsDisplayNames corresponds to a factor and must contain a vector with one element for each unique level in that factor. The level names are displayed in rows by factor along the x-axis.

    By default variabilitychart uses the categories found in the corresponding factor as the display names for the factor levels.

    Example: LevelsDisplayNames={["A1","A2","A3"],["B1","B2"]}

    Data Types: cell

    Indicator to add separators between the factor levels, specified as a positive integer or vector of positive integers. The integer values must be in the range [1,n] where n is the number of factors.

    The software adds a vertical grid line separator when the level changes for each factor specified by FactorsWithSeparators. If the level changes because of a change to a factor not specified in FactorsWithSeparators, the software does not add a separator.

    Example: FactorsWithSeparators=3

    Data Types: single | double

    Indicator to add boxes around the factor levels, specified as a positive integer or vector of positive integers. The integer values must be in the range [1,n] where n is the number of factors.

    The software adds a box around the level data for each factor specified by FactorsWithBoxes.

    Example: FactorsWithBoxes=2

    Data Types: single | double

    Indicator to add mean lines to the factor levels, specified as a positive integer or vector of positive integers. The integer values must be in the range [1,n] where n is the number of factors.

    The software adds horizontal lines at the mean value of each level for each factor specified by FactorsWithMeans.

    Example: FactorsWithMeans=1

    Data Types: single | double

    Indicator to color the factor levels, specified as a positive integer. The integer value must be in the range [1,n] where n is the number of factors. The software sets each of the unique levels in the specified factor to a different color.

    Example: FactorWithColors=4

    Data Types: single | double

    Target value, specified as a numeric scalar. The software adds a horizontal line at y = TargetValue and a label to the right of the y-axis. UseTargetValueLabel to customize the label.

    Example: TargetValue=12

    Data Types: single | double

    Output Arguments

    collapse all

    Variability chart, returned as a VariabilityChart object. Use v to set properties of the variability chart after creating it. For a list of properties, see VariabilityChart Properties.

    More About

    collapse all

    Version History

    Introduced in R2026b