Plot Mean over Box Charts using Positional and Color Grouping Variables
Show older comments
I'd like to plot mean over box chart which using positional and Color Grouping Variables.
Example)
tbl = readtable('TemperatureData.csv');
monthOrder = {'January','February','March','April','May','June','July', ...
'August','September','October','November''December'};
tbl.Month = categorical(tbl.Month,monthOrder);
boxchart(tbl.Month,tbl.TemperatureF,'GroupByColor',tbl.Year)
ylabel('Temperature (F)')
legend
hold on
meanTemperatureF = groupsummary(tbl.TemperatureF,{tbl.Month, tbl.Year}, 'mean');
plot(meanmeanTemperatureF,'o')
but, the positions of plot are not exactly.
How can I fix it?
3 Comments
dpb
on 11 Nov 2021
We can't see anything w/o data -- but other than
plot(meanmeanTemperatureF,'o')
isn't the same variable as calculated by
meanTemperatureF = groupsummary(tbl.TemperatureF,{tbl.Month, tbl.Year}, 'mean');
there's nothing to see that looks suspicious in the above code.
Would have to see the actual results to have any reason to suspect the computed means aren't the actual values given the input data.
KK
on 16 Nov 2021
dpb
on 16 Nov 2021
Well, you've got twelve months but for some reason only 11 categories on the boxplot axis and there are only 10+7 actual boxes by the time you've done the grouping by year.
Then you just plotted the means for an indeterminate number of months versus their ordinal positions.
You need to find/create the correct categorical variable value for each of those means that is associated with the position of the appropriate box -- and then since you have used grouping, that may still not quite line up.
Never done such an exercise before and suspect highly unlikely anybody on Answers has, either; attach your data as a .mat file so somebody can reproduce the result you have and easily explore how to make the necessary adjustments to axis values.
"Help us help you!"
Accepted Answer
More Answers (0)
Categories
Find more on Exploration and Visualization 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!
