I have a dataframe(df) with 3 columns:
test1 test2 res
500 23 30.75
200 23 31.36
110 26 30.38
105 23 31.57
55 21 33.56
35 21 31.39
27 18 36.89
23 23 35.44
I want to have one graph contians boxplots for both results. I have melted the data based on “res” and called the new one (df_melt) and I got the following:
res variable value
30.75 test1 500
31.36 test1 200
30.38 test1 110
31.57 test1 105
33.56 test1 55
31.39 test1 35
36.89 test1 27
35.44 test1 23
30.75 test2 23
31.36 test2 23
30.38 test2 26
31.57 test2 23
33.56 test2 21
31.39 test2 21
36.89 test2 18
35.44 test2 23
Now, I want to boxplot the data so, x-axis=res, and y-axis= value based on variable column. Therefore, I would expect two boxplots for each “res” value as I have two type of data in variable ( i.e.test1 and test2).
I have tried this :
boxplot(df_melt$value~df_melt$res)
I got only 8 boxplot and it is not clear for which test??? How I can add the second test to the graph so I can compare them.
The whole reason why I want to include them together so I can compare them ….
I suppose you are looking for a barplot, since you can’t generate a boxplot based on a single value.
Update: A boxplot solution based on the comment of the OP:
An analogous graph with multiple boxplots in different colours can be generated with:
Note that this graph only makes sense if you have multiple values in
valuesfor each combination ofresandvariable.The colours of the boxplots will be white and dark grey. You can modify the colour with the
scale_fill_manualfunction.