I have a Julia program that gives me data in the following form. For each point on X, I get a vector for the Y axis. I want to plot a boxplot for each X value using the vector of Y values. So I want the median to be the center of the boxplot and the error bars to basically be the first and the third quartile. Is there some inbuilt function in Julia which can help achieve this? If not, how do I go about this?
That is what
From your description, the data may need some pre-conditioning, for example:
using StatsPlots, DataFrames X = 0:2.5:10 n = length(X) Y = [rand(-3:3, 10) for _ in 1:n] X2 = [fill(x,length(y)) for (x,y) in zip(X,Y)] df = DataFrame(X = X2, Y = Y) @df df boxplot(:X, :Y, legend=false)
In case you would want to plot only the error bars around the median for the first and third quartiles, in the example above, you could do:
using Statistics Ym = median.(Y) ϵ⁻ = Ym .- quantile.(Y, fill(0.25, n)) ϵ⁺ = quantile.(Y, fill(0.75, n)) .- Ym scatter(X, Ym, ms=6, yerror=(ϵ⁻, ϵ⁺), legend=false)
@rafael.guerra Thank you for the answer, and please accept my apologies for the delay in my response. I was able to figure out the general boxplot on my own, but I didn’t get back to the forum soon enough. However, your other answer on displaying only the error bars is also very helpful. I’m likely going to end up using both.