scatterhistogramCreate a scatter plot with marginal histograms from a table of data for medical patients.
Load the
patientsdata set and create a table from a subset of the variables loaded into the workspace. Then, create a scatter histogram chart comparing the Heightvalues to the Weightvalues.
load patients tbl = table(LastName,Age,Gender,Height,Weight); s = scatterhistogram(tbl,'Height','Weight'); fig2plotly()
Using the
patientsdata set, create a scatter plot with marginal histograms and specify the table variable to use for grouping the data.Load the
patientsdata set and create a scatter histogram chart from the data. Compare the patients'SystolicandDiastolicvalues. Group the data according to the patients' smoker status by setting the'GroupVariable'name-value pair argument to'Smoker'.
load patients tbl = table(LastName,Diastolic,Systolic,Smoker); s = scatterhistogram(tbl,'Diastolic','Systolic','GroupVariable','Smoker'); fig2plotly()
Use a scatter plot with marginal histograms to visualize categorical and numeric medical data.
Load the
patientsdata set, and convert theSmokerdata to a categorical array. Then, create a scatter histogram chart that compares patients'Agevalues to their smoker status. The resulting scatter plot contains overlapping data points. However, the y-axis marginal histogram indicates that there are far more nonsmokers than smokers in the data set.
load patients
Smoker = categorical(Smoker);
s = scatterhistogram(Age,Smoker);
xlabel('Age')
ylabel('Smoker')
fig2plotly()
Create a scatter plot with marginal histograms using arrays of shoe data. Group the data according to shoe color, and customize properties of the scatter histogram chart.
Create arrays of data. Then, create a scatter histogram chart to visualize the data. Use custom labels along the x-axis and y-axis to specify the variable names of the first two input arguments. You can specify the title, axis labels, and legend title by setting properties of the
ScatterHistogramChartobject.
xvalues = [7 6 5 6.5 9 7.5 8.5 7.5 10 8];
yvalues = categorical({'onsale','regular','onsale','onsale', ...
'regular','regular','onsale','onsale','regular','regular'});
grpvalues = {'Red','Black','Blue','Red','Black','Blue','Red', ...
'Red','Blue','Black'};
s = scatterhistogram(xvalues,yvalues,'GroupData',grpvalues);
s.Title = 'Shoe Sales';
s.XLabel = 'Shoe Size';
s.YLabel = 'Price';
s.LegendTitle = 'Shoe Color';
fig2plotly()
Change the colors in the scatter histogram chart to match the group labels. Change the histogram bin widths to be the same for all groups.
s.Color = {'Red','Black','Blue'};
s.BinWidths = 1;
fig2plotly()
Create a scatter plot with marginal histograms. Specify the number of bins and line widths of the histograms, the location of the scatter plot, and the legend visibility.
Load the
patientsdata set and create a scatter histogram chart from the data. Compare the patients'DiastolicandSystolicvalues, and group the data according to the patients'SelfAssessedHealthStatusvalues. Adjust the histograms by specifying theNumBinsandLineWidthoptions. Place the scatter plot in the'NorthEast'location of the figure by using theScatterPlotLocationoption. Ensure the legend is visible by specifying theLegendVisibleoption as'on'.
load patients
tbl = table(LastName,Diastolic,Systolic,SelfAssessedHealthStatus);
s = scatterhistogram(tbl,'Diastolic','Systolic','GroupVariable','SelfAssessedHealthStatus', ...
'NumBins',4,'LineWidth',1.5,'ScatterPlotLocation','NorthEast','LegendVisible','on');
fig2plotly()
Create a scatter plot with marginal histograms. Group the data by using a combination of two different variables.
Load the
patientsdata set. Combine theSmokerandGenderdata to create a new variable. Create a scatter histogram chart that compares theDiastolicandSystolicvalues of the patients. Use the new variableSmokerGenderto group the data in the scatter histogram chart.
load patients
[idx,genderStatus,smokerStatus] = findgroups(string(Gender),string(Smoker));
SmokerGender = strcat(genderStatus(idx),"-",smokerStatus(idx));
s = scatterhistogram(Diastolic,Systolic,'GroupData',SmokerGender,'LegendVisible','on');
xlabel('Diastolic')
ylabel('Systolic')
fig2plotly()
Create a scatter plot with kernel density marginal histograms. This example requires a Statistics and Machine Learning Toolbox™ license.
Load the
carsmalldata set and create a scatter histogram chart from the data. Compare theHorsepowerandMPGvalues. Use the number of cylinders to group the data by setting theGroupVariableoption toCylinders. Specify kernel density histograms by setting theHistogramDisplayStyleoption to'smooth'. Specify a solid line for all the histograms by setting theLineStyleoption to'-'.
load carsmall
tbl = table(Horsepower,MPG,Cylinders);
s = scatterhistogram(tbl,'Horsepower','MPG', ...
'GroupVariable','Cylinders','HistogramDisplayStyle','smooth', ...
'LineStyle','-');
fig2plotly()