raincloudplot
Syntax
Description
Vector and Matrix Data
raincloudplot( creates a rain cloud plot
for each column of the matrix ydata)ydata. If ydata is
a vector, then raincloudplot creates a single rain cloud plot.
raincloudplot(
groups the data in xgroupdata,ydata)ydata according to the unique values in
xgroupdata and plots each group of data as a separate rain cloud
plot. xgroupdata determines the position of each rain cloud plot
along the y-axis.
Table Data
raincloudplot(
creates a rain cloud plot of the data in tbl,xvar,yvar)yvar grouped by the data in
xvar, where xvar and yvar
are variables from the table tbl. To plot one data set, specify one
variable for xvar and one variable for yvar. To plot
multiple data sets, specify multiple variables for xvar,
yvar, or both. If both arguments specify multiple variables, they
must specify the same number of variables.
Additional Options
raincloudplot(___,
sets plot properties using one or more name-value arguments in addition to any of the
input argument combinations in the previous syntaxes. For example, you can specify the
plot orientation and marker symbol. For a list of properties, see RainCloudPlot Properties.Name=Value)
returns a
r = raincloudplot(___)RainCloudPlot object or a vector of RainCloudPlot
objects. Use r to set properties of the rain cloud plots after
creating them. For a list of properties, see RainCloudPlot Properties.
Examples
Create a single rain cloud plot from a vector of patient ages. Use the rain cloud plot to analyze the distribution of ages.
Load the patients data set. The Age vector contains the ages of 100 patients. Create a rain cloud plot to visualize the distribution of ages.
load patients raincloudplot(Age) xlabel("Age (years)")

The upper half of the rain cloud plot is a violin plot whose outline is determined by the kernel density estimate (kde) for the probability density function. The kde is bell-shaped with a peak near 40 on the vertical axis. The plot shows that the data in Age is approximately normally distributed and the median patient age is around 40. The lower half of the rain cloud plot is a swarm chart, which is a scatter plot with the points offset in the y-direction.
Generate a matrix of normally distributed random numbers. Create a rain cloud plot for the data in each column of the matrix.
ydata = randn(100,3); raincloudplot(ydata)

The three rain cloud plots have group labels 1, 2, and 3. The shapes of the rain cloud plots are slightly different due to randomness in the data. However, each rain cloud plot has the bell-shape characteristic of a normal distribution.
Generate a vector of normally distributed random numbers and a vector of grouping data.
ydata = randn(100,1); xgroupdata = categorical(repelem(["group1";"group2";"group3"],[20,50,30]));
Create a set of rain cloud plots for the data in ydata grouped by the unique values in xgroupdata. Each rain cloud plot in the figure corresponds to a unique value in xgroupdata.
raincloudplot(xgroupdata,ydata)

Load the tsunami data set into a table. Create rain cloud plots for the Longitude and Latitude variables.
tbl = readtable("tsunamis.xlsx"); raincloudplot(tbl,["Longitude","Latitude"])

Generate two vectors of normally distributed data and three vectors of grouping data.
ydata1 = randn(100,1); ydata2 = randn(100,1)+5; xgroupdata1 = categorical(repelem(["group1";"group2"],[90,10])); xgroupdata2 = categorical(repelem(["group1";"group2"],[10,90])); xgroupdata3 = categorical(repelem(["group3";"group4"],[25,75]));
The variables ydata1 and ydata2 contain normally distributed data with means of 0 and 5, respectively. xgroupdata1 and xgroupdata2 contain different sequences of the same group labels. xgroupdata3 contains different group labels from those in xgroupdata1 and xgroupdata2.
Create a table from the sample data and grouping data.
tbl = table(xgroupdata1,xgroupdata2,xgroupdata3, ... ydata1,ydata2,VariableNames=["X1","X2","X3","Y1","Y2"]);
Create a set of overlaid rain cloud plots using the data in Y1 grouped by X1 and X2.
raincloudplot(tbl,["X1","X2"],"Y1")

The figure shows two sets of overlaid rain cloud plots. The blue rain cloud plots represent the data in Y1 grouped by X1, and the orange rain cloud plots represent the same data grouped by X2. The overlaid plots show that the different groupings do not significantly change the median values for each group. However, the different groupings have a visible effect on the shape of the rain cloud plots corresponding to each group. This result suggests that the distribution of the data in each group is affected by how the data is grouped.
Create another set of rain cloud plots using the data in Y1 grouped by X1 and the data in Y2 grouped by X3.
raincloudplot(tbl,["X1","X3"],["Y1","Y2"])

The blue plots corresponding to groups 1 and 2 represent the data in Y1, and the orange plots corresponding to groups 3 and 4 represent the data in Y2. The plots show that the median values for the data in groups 3 and 4 are larger than those for groups 1 and 2.
Create rain cloud plots from patient data to compare the blood pressure of smokers and nonsmokers. The plots show that smokers have higher average systolic and diastolic blood pressure than nonsmokers.
Load the patients data set.
load patientsCreate a 1-by-2 tiled chart layout using the tiledlayout function. Create the first set of axes ax1 by calling the nexttile function. In the first set of axes, display two rain cloud plots representing the systolic blood pressure values, one for smokers and the other for nonsmokers. Create the second set of axes ax2 within the tiled chart layout by calling the nexttile function. In the second set of axes, do the same for diastolic blood pressure.
tiledlayout(1,2) % Left axes ax1 = nexttile; raincloudplot(ax1,categorical(Smoker),Systolic) xlabel(ax1,"Systolic Blood Pressure") ylabel(ax1,"Smoker") % Right axes ax2 = nexttile; raincloudplot(ax2,categorical(Smoker),Diastolic) xlabel("Diastolic Blood Pressure") ylabel(ax2,"Smoker")

Load the patients data set.
load patientsThe variables Diastolic and Smoker contain data for patient diastolic blood pressure and smoker status.
Create two vectors containing the diastolic blood pressure data for smokers and nonsmokers, respectively.
diastolicSmoker=Diastolic(Smoker==1); diastolicNonSmoker=Diastolic(Smoker==0);
Create a set of rain cloud plots using the diastolic blood pressure data for smokers and nonsmokers.
figure
hold on
r1 = raincloudplot(diastolicSmoker);
r2 = raincloudplot(diastolicNonSmoker);You can modify the rain cloud plots by specifying the properties of the RainCloudPlot objects in r1 and r2. For more information, see RainCloudPlot Properties.
Update the colors of the raincloud plots so that the plot for smokers is green and the plot for nonsmokers is magenta.
r1.FaceColor="g"; r2.FaceColor="m"; legend("Smoker","Nonsmoker")

Input Arguments
Sample data, specified as a numeric vector or matrix.
If
ydatais a matrix, thenraincloudplotcreates a rain cloud plot for each column ofydata.If
ydatais a vector and you do not specifyxgroupdata, thenraincloudplotcreates a single rain cloud plot.If
ydatais a vector and you specifyxgroupdata, thenraincloudplotcreates a rain cloud plot for each unique value inxgroupdata.
Data Types: single | double
Positional grouping data, specified as a numeric or categorical vector, or a numeric or categorical matrix.
If
ydatais a vector of length n, thenxgroupdatamust be a vector of length n or a matrix with n rows.If
ydatais a matrix, thenxgroupdatamust be a matrix of the same size or a vector of length equal to the number of rows or columns inydata.
raincloudplot groups the data in ydata
according to the unique values in xgroupdata and creates a rain
cloud plot for each group. By default, raincloudplot horizontally
orients the rain cloud plots and displays the xgroupdata values
along the y-axis. You can change the rain cloud plot orientation by
using Orientation.
Data Types: single | double | categorical
Source table containing the data to plot, specified as a table or timetable.
Table variables containing the sample data, specified as one or more table variable indices. The table variables you specify must contain numeric values.
Specifying Table Indices
Use any of the following indexing schemes to specify the intended variable or variables.
| Indexing Scheme | Examples |
|---|---|
Variable names:
|
|
Variable indices:
|
|
Variable type:
|
|
Plotting Your Data
To plot one set of rain cloud plots, specify one variable for
xvar and one variable for yvar. For example,
create a table with two categorical grouping variables and one variable containing
normally distributed random values. Plot the data in Y grouped by
the data in
X1.
X1 = categorical(repelem(["a1";"b1"],50)); X2 = categorical(repelem(["a2";"b2";"c2"],[33,33,34])); Y = randn(100,1); tbl = table(X1,X2,Y); raincloudplot(tbl,"X1","Y")
To plot multiple data sets together, specify multiple variables for
xvar, yvar, or both. If you specify multiple
variables for both arguments, the number of variables for each argument must be the
same.
For example, create a set of rain cloud plots from the data in
Y using X1 as the grouping variable, and a set
using X2 as the grouping
variable.
raincloudplot(tbl,["X1","X2"],"Y")
You can also use different indexing schemes for xvar and
yvar. For example, specify xvar as a variable
name and yvar as an index
number.
raincloudplot(tbl,"X1",3)Table variables containing the positional grouping data, specified as one or more table variable indices. The table variables you specify must contain numeric or categorical values.
Specifying Table Indices
Use any of the following indexing schemes to specify the intended variable or variables.
| Indexing Scheme | Examples |
|---|---|
Variable names:
|
|
Variable indices:
|
|
Variable type:
|
|
Plotting Your Data
To plot one set of rain cloud plots, specify one variable for
xvar and one variable for yvar. For example,
create a table with one categorical grouping variable and two variables containing
normally distributed random values. Plot the data in Y1 grouped by
the data in
X.
X = categorical(repelem(["a1";"b1"],50)); Y1 = randn(100,1); Y2 = 5*randn(100,1)+10; tbl = table(X,Y1,Y2); raincloudplot(tbl,"X","Y1")
To plot multiple data sets together, specify multiple variables for
xvar, yvar, or both. If you specify multiple
variables for both arguments, the number of variables for each argument must be the
same.
For example, create a set of rain cloud plots from the data in
Y1 using X as the grouping variable, and a set
using Y2 as the
data.
raincloudplot(tbl,"X",["Y1","Y2"])
You can also use different indexing schemes for xvar and
yvar. For example, specify xvar as a variable
name and yvar as an index
number.
raincloudplot(tbl,"X",3)Target axes, specified as an Axes object. If you do not specify the
axes, then raincloudplot uses the current axes
(gca).
Name-Value Arguments
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: raincloudplot(ydata,Orientation="vertical",MarkerEdgeColor="g",MarkerFaceColor="g")
uses the data in ydata to create a vertical rain cloud plot with green
markers.
Note
The RainCloudPlot properties listed here are only a subset. For a
complete list, see RainCloudPlot Properties.
Maximum rain cloud plot width, specified as a positive scalar.
DensityWidth has the same units as the positional grouping data
specified by xgroupdata or xvar.
Example: DensityWidth=0.5
Data Types: single | double
Orientation of the rain cloud plots, specified as "horizontal"
or "vertical". By default, the rain cloud plots are horizontally
oriented so that the rain cloud plots align with the x-axis.
Regardless of the orientation, raincloudplot stores the sample data
in the YData property of the RainCloudPlot
object.
Example: Orientation="vertical"
Data Types: string | char
Output Arguments
Rain cloud plots, returned as a RainCloudPlot object or a vector of
RainCloudPlot objects.
Use r to set properties of the rain cloud plots
after creating them. For a list of properties, see RainCloudPlot Properties.
More About
A rain cloud plot provides a visual representation of a data sample and
its corresponding empirical distribution. One half of a rain cloud plot is a violin plot,
and the other half is a swarm chart. For more information, see swarmchart and
violinplot.
Version History
Introduced in R2026a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)