# Plot mean of data with error bar

Suppose I have the following data with co-ordinates: {{1,190},{1,200},{1,210},{1,180},{1.5,175},{1.5,200},{1.5,190},{2,100},{2,150}}

How do I make a listplot of this data set, by taking the mean of the y-values for a particular x-value and then plotting an error bar. Since this is a small data set, I can evaluate mean and error easily, but what of there is a large data set, is there some way to automate the process?

data = {{1, 190}, {1, 200}, {1, 210}, {1, 180}, {1.5, 175}, {1.5,
200}, {1.5, 190}, {2, 100}, {2, 150}} ;

data2 = KeyValueMap[List]@ GroupBy[data, First -> Last, Around] (*thanks: Lukas Lang*)

ListPlot[data2]


ListPlot[data2,
PlotStyle -> Directive[Blue, PointSize[Large]],
"FenceStyle" -> Directive[Thick, Red],
"WhiskerStyle" -> Directive[Green, CapForm["Butt"], AbsoluteThickness[20]]|>]


ListPlot[data2, Joined -> True,
IntervalMarkers -> "Bands", IntervalMarkersStyle -> Green, PlotRange -> {0, 220}]


• Thank you, can you tell e what attribute should I change to change the color, boldness etc. of the error bar? Commented Oct 7, 2020 at 20:39
• @Indeterminate, please see the update.
– kglr
Commented Oct 7, 2020 at 21:59
• You should be able to just use Around[#], and Around will automatically compute the mean and standard deviation (see the fourth usage case in the docs) Commented Oct 8, 2020 at 7:43
• Thank you @LukasLang; excellent point. Updated with your suggestion.
– kglr
Commented Oct 8, 2020 at 7:52
• @kglr the solution with the 'whiskers' does not work on logarithmic axes. can it be adapted? Commented Oct 8, 2020 at 9:32