Plotting 2 data points per subject with connected line

I am trying to plot 2 different values on a shared scale (e.g. scores on two different tests) per subject with a line connecting both scores per subject rather than a continuous line connecting each set of scores for all subjects. See my doodle for hopefully a more clear visual representation :) Thanks in advance

1 comentario

E G
E G el 15 de Jul. de 2022
I should add that the more typical display with 2 data points per subject in this fashion won't work because of the amount of participants and overlap:

Iniciar sesión para comentar.

 Respuesta aceptada

var1 = [5 3 8 5 12];
var2 = [8 10 5 7 6];
N = numel(var1);
plot(1:N,var1,'o')
hold on
plot(1:N,var2,'x')
x_temp = repmat(1:N,3,1);
y_temp = [var1(:) var2(:) NaN(numel(var1),1)].';
plot(x_temp(:),y_temp(:),'k')
xlim([0 10])
ylim([0 15])

4 comentarios

E G
E G el 15 de Jul. de 2022
Thank you! This works perfectly except it overrides the vertical lines for continuous lines as soon as I change marker properties (e.g. "Marker",'o',"MarkerSize",9,"MarkerEdgeColor",'k',"MarkerFaceColor",[0.552 0.316 0.132]). Any insight?
Voss
Voss el 16 de Jul. de 2022
Set 'LineStyle', 'none' along with those other properties.
E G
E G el 16 de Jul. de 2022
Voila, looks perfect, thanks again!
Voss
Voss el 16 de Jul. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

E G
el 15 de Jul. de 2022

Comentada:

el 16 de Jul. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by