从2个不同的数据框中创建配对的箱线图 [英] Create paired boxplots, from 2 distinct dataframes
本文介绍了从2个不同的数据框中创建配对的箱线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在R中创建带有箱形图的图形。我得到以下数据框:
I would like to create a graphic with box plot in R. I got the following data frames:
> drools_responseTimes_numberOfClients_REST
X1 X5 X10 X20 X50
1 816 183 699 154 297
2 366 280 1283 345 291
3 103 946 1609 409 377
4 431 1086 1974 482 479
5 90 1379 2083 567 557
6 290 511 2184 910 925
7 134 770 2283 980 1277
8 480 1547 2416 1069 1752
9 275 1727 2520 1141 1846
10 67 679 2616 1188 1935
> javascript_responseTimes_numberOfClients_REST
X1 X5 X10 X20 X50
1 334 497 610 439 417
2 445 894 859 826 588
3 306 1143 1123 1407 791
4 301 1442 1445 1806 1005
5 257 1754 1857 2209 1235
6 181 507 2078 2493 1441
7 436 1186 2419 2885 1677
8 353 2280 2708 3101 1909
9 350 2984 2997 3358 2106
10 296 544 3185 3817 2353
我想为每个区分列创建成对的箱形图按颜色显示类型,如下所示: https://stackoverflow.com/a/17922219/3503168
I want to create paired box plot for each column distinguishing the type by the color as shown here: https://stackoverflow.com/a/17922219/3503168
推荐答案
我建议使用ggplot + reshape2和随机数据的解决方案:
I suggest a solution using ggplot+reshape2, with random data:
set.seed(10)
drools <- data.frame(matrix(round(runif(50, 50, 1000)), ncol=5))
java <- data.frame(matrix(round(runif(50, 50, 1000)), ncol=5))
library(ggplot2)
library(reshape2)
df <- data.frame(melt(drools), melt(java)[2])
names(df) <- c("column", "drools", "java")
df2 <- melt(df)
ggplot(data=df2) +
geom_boxplot(aes(x=column, y=value, fill=variable))
它给出:
融化实际上的作用是将5列(然后是第二个使用2列)转换为一个列中的因子,这使绘制过程变得容易。
What 'melt' actually does is transform the 5 (then 2 for the second use) columns into factors inside one single colum, which makes it easy for plotting.
这篇关于从2个不同的数据框中创建配对的箱线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文