Plot different conditions & subjects at once in Mathematica
Please Consider :
Needs["ErrorBarPlots`"];
fixNumberF1F6 = {{{7.11`, 7.51`, 11.14`, 8.19`, 6.58`},
{2.14`, 2.33`,2.25`, 1.53`,1.71`}},
{{4.69`, 4.79`, 3.78,4.34`, 4.8`},
{2.22`, 2.71`, 3.18`, 2.29`, 1.93`}}}
fixNumberF1F6[[1,1]] refers to the mean fixation number for each subject for condition 1, fixNumberF1F6[[1,2]] the standard Deviation of those means. fixNumberF1F6[[2]] refers to condition 2.
plotOptionsXX[title_, yName_, xName_, colors_: Black] :=
{Frame -> {{True, False}, {True, False}},
PlotStyle -> colors,
PlotLabel ->
Style[title, Bold, 14, Opacity[1], FontFamily -> "Helvetica"],
PlotStyle -> Directive[Black, PointSize[Medium]],
PlotRangePadding -> 0,
Frame -> {{True, False}, {True, False}},
LabelStyle -> Directive[Black, Bold, 12],
FrameLabel -> {{Style[yName, Opacity[1]],
None}, {Style[xName, Opacity[1]], None}},
FrameStyle -> Opacity[0],
FrameTicksStyle -> Opacity[1],
AxesStyle -> Directive[Black, 12],
ImageSize -> laTaille};
ErrorListPlot[fixNumberF1F6[[#]] // Transpose,
PlotRange -> {{0, 6}, {0, 15}},
ImageSize -> 300,
FrameTicks ->{{Range[1, 13, 2], None},{{1, 2, 3, 4, 5}, None}},
PlotStyle -> Directive[Black, AbsolutePointSize[10], AbsoluteThickness[2]],
plotOptionsXX["Mean Fixation number", "Fixation Nuber", "SubNo"]] & /@ Range[2]
The Plot On the Left represent each subject average fixation number along with the standard deviation for condition 1. On the right for condition 2.
How could I plot them both on 1 plot ?
If this :
fixNumberF1F6across = {{8.10, 1.99}, {4.48, 2.46}}
was the mean and SD across subject, How could I show both ?
-How can I show 2 conditions on a similar plot for different subjects -How could I show the group mean and SD on it to.
Edit :
I started from over. Given how the data are simple and clean, it may be easiest to use ListPlot
and add the bars via an Epilog
.
You can still tweak it a bit--eg put a slight space between the blue and red data points and bars, add a legend, etc, but the basic idea is there.
data = {{{7.11`, 7.51`, 11.14`, 8.19`, 6.58`}, {2.14`, 2.33`, 2.25`, 1.53`, 1.71`}}, {{4.69`, 4.79`, 3.78, 4.34`, 4.8`}, {2.22`, 2.71`, 3.18`, 2.29`, 1.93`}}};
ListPlot[{data[[1, 1]], data[[2, 1]]},
PlotStyle -> {{PointSize[.025], Red}, {PointSize[0.025], Blue}},
Frame -> True,
PlotRange -> {{0.5, 5.5}, {0, 14}},
FrameTicks -> {{Automatic, Automatic}, {Range[5], None}},
FrameLabel -> {{"Fixation (ms)", None}, {"Subject", None}},
Epilog -> {{Red, Thickness[0.003], Dashed,
Line[{{0, m1 = Mean@data[[1, 1]]}, {5.5, m1}}],
Blue, Line[{{0, m1 = Mean@data[[2, 1]]}, {5.5, m1}}]},
Thickness[0.005], Red,
Line[{{#[[1]], #[[2, 1]]}, {#[[1]], #[[2, 2]]}}] & /@
Transpose@{Range[5], ({#[[1]] + #[[2]], #[[1]] - #[[2]]} & /@
Transpose@data[[1]])},
Thickness[0.005], Blue,
Line[{{#[[1]], #[[2, 1]]}, {#[[1]], #[[2, 2]]}}] & /@
Transpose@{Range[5], ({#[[1]] + #[[2]], #[[1]] - #[[2]]} & /@
Transpose@data[[2]])},
}]
The BoxWhiskerChart
below is from your data. If this looks vaguely like something you are interested in, it could be modified so that the spread from the 25th percentile to the 75% percentile is altered to reflect the spread of one sd above and below the mean.
And, yes, it is easy to overlay the group means (N=5) onto the Chart.
[The reason there isn't perfect symmetry around the mean is that I used your means and standard deviations to generate raw data, assuming a normal distribution. I only used 100 data points per trial, so a little skewing is natural. This would not happen if we were to tweak the chart to reflect standard deviations, which are symmetrical.]
For any number of series:
plotseries[a_] :=
Module [{col = ColorData[22, "ColorList"]},
Plot[Evaluate@(Piecewise[{#[[2]], #[[1]] - 1/3 <= x <= #[[1]] + 1/3} & /@
Thread[List[Range@Length@#, #]]] & /@
({a[[#, 1]] + a[[#, 2]], a[[#, 1]] - a[[#, 2]]}) & /@
(Range@Length@a)), {x, 0, 1 + Length@(a[[1, 1]])},
ClippingStyle -> None,
PlotStyle -> {None},
Exclusions -> False,
Filling -> ({2 # - 1 -> {{2 #}, Directive[col[[#]], Opacity[.2]]}} & /@
Range@Length@a),
Ticks -> {Range@Length[a[[1, 1]]], Range@#2 &},
AxesLabel -> {Style["Subject", Medium, Bold], Style["Fixation Time", Medium, Bold]},
Epilog ->
MapIndexed[{Directive[col[[#2[[1]]]], PointSize[.03]],
Point@Thread[List[Range@Length[#1[[1]]], #1[[1]]]]} &, a]
]
]
b = Table[{Table[j^(i/3) + i, {j, 6}], Table[1, {j, 6}]}, {i, 1, 3}];
plotseries[b]
I don't work very much with error plots, so this might very well be a non-standard form of displaying the data and hastily put together based on the example in the documentation for ErrorBarFunction
.
(*split it up so it's easier to follow*)
meanCond1 = fixNumberF1F6[[1, 1]];
stdCond1 = fixNumberF1F6[[1, 2]];
meanCond2 = fixNumberF1F6[[2, 1]];
stdCond2 = fixNumberF1F6[[2, 2]];
x1 = Transpose@{meanCond1, meanCond2};
x2 = ErrorBar @@@ Transpose@{stdCond1, stdCond2};
Show@(ErrorListPlot[{#1},
ErrorBarFunction ->
Function[{coords, errs}, {Opacity[0.2], EdgeForm[{#2}],
Rectangle[coords + {errs[[1, 1]], errs[[2, 1]]},
coords + {errs[[1, 2]], errs[[2, 2]]}]}], PlotStyle -> #2,
Axes -> False, Frame -> True,
FrameLabel -> {"Condition 1", "Condition 2"}] & @@@
Transpose@{Transpose@{x1, x2}, {Blue, Yellow, Green, Gray, Red}})
Each dot is a different subject. The x
coordinate is the mean for condition 1 and the y
coordinate is the mean for condition 2. The lengths of the sides of the rectangles are the respective standard deviations. So while it does overlap, if you're prudent in choosing colors (and if there aren't too many subjects), it could perhaps work.
上一篇: 在Mathematica中绘制最佳曲线