Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a boxplot for each x value?

I have a plot with a set of points for different x values: 5 points for x=0.5, 5 points for x=0.6, ..., 5 points for x=1.4, 5 points for x=1.6.

Now I want to create a boxplot for each of those x values. But somehow all my boxplots are at x=0.5. I want the boxplots to be created at the right x value. The distance between 2 x values can be different. My current x values are 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.4 and 1.6, but they could also be different for a different plot. How would I do that?

This is the GNUPlot script for my points: https://dl.dropboxusercontent.com/u/26464165/Points.gnu

This is the GNUPlot script for my boxplots: https://dl.dropboxusercontent.com/u/26464165/Boxplots.gnu

Thanks for your time!

like image 353
John Avatar asked Apr 27 '14 18:04

John


People also ask

How do I create a box plot in Matplotlib?

Creating Box Plot. The matplotlib.pyplot module of matplotlib library provides boxplot() function with the help of which we can create box plots. Syntax: matplotlib.pyplot.boxplot(data, notch=None, vert=None, patch_artist=None, widths=None) Parameters:

What are boxplots?

The tutorial will contain these topics: Here’s how to do it… Boxplots are a popular type of graphic that visualize the minimum non-outlier, the first quartile, the median, the third quartile, and the maximum non-outlier of numeric data in a single plot. Let’s create some numeric example data in R and see how this looks in practice:

How to plot a boxplot in base R?

The boxplot function in R. A box and whisker plot in base R can be plotted with the boxplot function. You can plot this type of graph from different inputs, like vectors or data frames, as we will review in the following subsections. In case of plotting boxplots for multiple groups in the same graph, you can also specify a formula as input.

How do I create a graphic with multiple boxplots in Excel?

Now, we can store our three variables x, y, and z in a data frame: If we want to create a graphic with multiple boxplots, we have to specify a column containing our numeric values, the grouping column, and the data frame containing our data: Figure 2: Multiple Boxplots in Same Graphic.


1 Answers

You must rearrange your data for the boxplots. The statistics are computed over complete columns. So, you must rearrange your data like:

# 1.0 1.2 1.4 ...
2.2 2.2 3.06
2.0 2.46 2.93
2.2 2.46 3.06
2.0 2.4 2.8
1.73 2.33 2.8

Then you can plot it with:

set style fill solid 0.25 border -1
set style boxplot outliers pointtype 7
set style data boxplot

set title 'My Plot' font 'Arial,14';
set xtics ('1.0' 1, '1.2' 2, '1.4' 3)
plot for [i=1:3] 'data.txt' using (i):i notitle

The result with 4.6.4 is:

enter image description here

Instead of writing the xtics manually, you could extract them (with Unix commandline tools), like shown e.g. in https://stackoverflow.com/a/10799204/2604213:

header = "`head -1 data.txt | cut -b 2-`"
set for [i=1:words(header)] xtics (word(header, i) i)
like image 113
Christoph Avatar answered Sep 22 '22 20:09

Christoph