Overlay a scatterplot of continuous data with boxplots summarizing groupings of the same data
Show older comments
I have a scatterplot of continous x-y data values, where the x data is time
x=[1:100];
and the y data are measured data values at each time point. For example Y data, lets use 100 random values between 150 and 200:
y = (200-150).*rand(100,1) + 150)
Separately, I've also split the y-value data into 3 groups based on which segment of time they were meausured (group1: x-values from 0-33, group2: x-values from 33-66, etc), and calculated summary statistics of the corresponding y-data for each group. I would like to overlay a boxplot of the summary statistics for each group onto the scatterplot of the continuous data.
figure; ax1=scatter(x, y, [ ], [0.5 0.5 0.5], 'filled', 'MarkerFaceAlpha', .05, 'MarkerFaceColor',[0.5 0.5 0.5] );
xticks(0:20:100);
This scatterplot has xticks and xticklabels from [0:20:100].
I then use "hold on" to create a boxplot over the scatterplot, where I specify the placement of the boxes along the x-axis of the scatterplot to correspond to the center x-value of each group.
x_group_labels=vertcat(ones(1,33)',ones(1,33)'*2,ones(1,34)'*3);
hold on; boxA=boxplot(y, x_group_labels, 'symbol', '','Positions', [17,49.5,83]);
However, while the boxplots are properly placed over the scatterplot data in the correct figure location (x=[17,49.5,83] of the scatterplot), the xticks and xlabels have changed so that only the boxplot group number (e.g. "1", "2" ,"3") is visible under each boxplot.
I would like to keep the original x-axis display of the scatterplot and not the boxplot but try as I might, I'm not able to figure out how to accomplish this. Any assistance or tricks would be immensely appreciated.
Accepted Answer
More Answers (1)
CAM
on 16 Feb 2023
0 votes
Have you tried plotting the boxplot on the secondary y-axis and hide its x-labels?
1 Comment
Adam Smith
on 16 Feb 2023
Edited: Adam Smith
on 16 Feb 2023
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!