scatterhistogram
Create a scatter plot with marginal histograms from a table of data for medical patients.
Load the
patients
data set and create a table from a subset of the variables loaded into the workspace. Then, create a scatter histogram chart comparing the Height
values to the Weight
values.
load patients tbl = table(LastName,Age,Gender,Height,Weight); s = scatterhistogram(tbl,'Height','Weight'); fig2plotly()
Using the
patients
data set, create a scatter plot with marginal histograms and specify the table variable to use for grouping the data.Load the
patients
data set and create a scatter histogram chart from the data. Compare the patients'Systolic
andDiastolic
values. 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
patients
data set, and convert theSmoker
data to a categorical array. Then, create a scatter histogram chart that compares patients'Age
values 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
ScatterHistogramChart
object.
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
patients
data set and create a scatter histogram chart from the data. Compare the patients'Diastolic
andSystolic
values, and group the data according to the patients'SelfAssessedHealthStatus
values. Adjust the histograms by specifying theNumBins
andLineWidth
options. Place the scatter plot in the'NorthEast'
location of the figure by using theScatterPlotLocation
option. Ensure the legend is visible by specifying theLegendVisible
option 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
patients
data set. Combine theSmoker
andGender
data to create a new variable. Create a scatter histogram chart that compares theDiastolic
andSystolic
values of the patients. Use the new variableSmokerGender
to 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
carsmall
data set and create a scatter histogram chart from the data. Compare theHorsepower
andMPG
values. Use the number of cylinders to group the data by setting theGroupVariable
option toCylinders
. Specify kernel density histograms by setting theHistogramDisplayStyle
option to'smooth'
. Specify a solid line for all the histograms by setting theLineStyle
option to'-'
.
load carsmall tbl = table(Horsepower,MPG,Cylinders); s = scatterhistogram(tbl,'Horsepower','MPG', ... 'GroupVariable','Cylinders','HistogramDisplayStyle','smooth', ... 'LineStyle','-'); fig2plotly()