Boxplot and Plot Overlay Problem

2 visualizzazioni (ultimi 30 giorni)
Ioannis
Ioannis il 28 Mar 2023
Risposto: VBBV il 29 Mar 2023
Hello, I am new to Matlab
I happen to want to plot a trendline over a boxplot (same graph, same X-axis and different Y-axis but the Y-values are on the same scale).
All the vectors (X(=year), Y1(=diox), Y2(=c)) are the same size:1x191 double.
diox are 191 different values which are assigned to a "year".
year are 191 values allthough there are many replicates (eg. the value 2005 appears 7 times etc.)
c are 191 values that correspond to the mean of each "year" for the "diox" which were created with a for-if loop - I thought that it would be easier to have the exact same X-axis which is "year".
When it runs, I get the boxplot but I don't get the plot (although I get the yyaxis right axis correct).
Any help would be appreciated!
figure;
xlim([2004 2022]); ylim([0 1.5])
yyaxis left
boxplot(diox,year);
hold on
ylabel('WHO-PCDD/F-TEQ/product')
yyaxis right
plot(c,year)
ylabel('Annual TEQ Means')
title(sprintf('Dioxins'))
hold off
  1 Commento
Adam Danz
Adam Danz il 28 Mar 2023
It would be easier to troubleshoot if you attach the data.

Accedi per commentare.

Risposte (1)

VBBV
VBBV il 29 Mar 2023
As you say, X, Y1 , Y2 are same size and since Y2 (c) is a vector with mean of each year, plot the graph using the unique values of the year against the X (year)
figure;
xlim([2004 2022]); ylim([0 1.5])
yyaxis left
boxplot(diox,year);
hold on
ylabel('WHO-PCDD/F-TEQ/product')
yyaxis right
% ------------------>>>
plot(c,unique(year)) % take the unique year values
ylabel('Annual TEQ Means')
title(sprintf('Dioxins'))
hold off
Also, when you say,
c are 191 values that correspond to the mean of each "year" for the "diox" which were created with a for-if loop
how do you get 191 values when you calculate mean for each year ?
Data for repetitve occurances of the same year are considered as one set, and mean of that data must yield a scalar
Could you show us how your for-loop code is built ? If possible attach your data as well.

Prodotti


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by