R:在同一图上可视化多组数据

时间:2015-09-17 20:21:58

标签: r plot visualization

library(SKAT)
dput(power_1)
structure(list(Power = structure(c(0.0904911238503488, 0.116896940171286, 
0.133660828310703, 0.145485514611059, 0.155043218367765, 0.163752946488252, 
0.17218327988806, 0.180497367431762, 0.188711344672874, 0.196812056831157, 
0.204802490598304, 0.212705048819388, 0.220546055088385, 0.228344632876145, 
0.236100868362989, 0.24380212327874, 0.251430030755802, 0.258965792370089, 
0.266392808787985, 0.273697560713143), .Dim = c(20L, 1L), .Dimnames = list(
    c("500", "1000", "1500", "2000", "2500", "3000", "3500", 
    "4000", "4500", "5000", "5500", "6000", "6500", "7000", "7500", 
    "8000", "8500", "9000", "9500", "10000"), "0.05"))), .Names = "Power", class = "SKAT_Power")

dput(power_2)
structure(list(Power = structure(c(0.108146899211234, 0.149290374433909, 
0.178872420848407, 0.201697710495393, 0.221011543649422, 0.23826875582574, 
0.254015907163468, 0.268682373148783, 0.282638405711179, 0.296105120560091, 
0.309179769845385, 0.321905312760823, 0.334315018553888, 0.346450865211257, 
0.358368710065157, 0.370135859012643, 0.381823395046751, 0.393496249249642, 
0.405204349821764, 0.416977195149242), .Dim = c(20L, 1L), .Dimnames = list(
    c("500", "1000", "1500", "2000", "2500", "3000", "3500", 
    "4000", "4500", "5000", "5500", "6000", "6500", "7000", "7500", 
    "8000", "8500", "9000", "9500", "10000"), "0.05"))), .Names = "Power", class = "SKAT_Power")

> power_1
$Power
            0.05
500   0.09049112
1000  0.11689694
1500  0.13366083
2000  0.14548551
2500  0.15504322
3000  0.16375295
3500  0.17218328
4000  0.18049737
4500  0.18871134
5000  0.19681206
5500  0.20480249
6000  0.21270505
6500  0.22054606
7000  0.22834463
7500  0.23610087
8000  0.24380212
8500  0.25143003
9000  0.25896579
9500  0.26639281
10000 0.27369756

attr(,"class")
[1] "SKAT_Power"
> power_2
$Power
           0.05
500   0.1081469
1000  0.1492904
1500  0.1788724
2000  0.2016977
2500  0.2210115
3000  0.2382688
3500  0.2540159
4000  0.2686824
4500  0.2826384
5000  0.2961051
5500  0.3091798
6000  0.3219053
6500  0.3343150
7000  0.3464509
7500  0.3583687
8000  0.3701359
8500  0.3818234
9000  0.3934962
9500  0.4052043
10000 0.4169772

attr(,"class")
[1] "SKAT_Power"

我有两组数据,power_1power_2。我想将它们绘制在同一图表上,第一列在x轴上,第二列在y轴上。我试图将两个数据集合起来(比如rbind),但由于它们属于SKAT_Power类,因此无法正常工作。我该如何绘制这些数据?

1 个答案:

答案 0 :(得分:1)

我是使用data.tableggplot2

完成的
dt1 <- data.table(x=as.numeric(rownames(power_1$Power)), y=power_1$Power, z='dt1')
dt2 <- data.table(x=as.numeric(rownames(power_2$Power)), y=power_2$Power, z='dt2')
DT <- rbind(dt1, dt2)
ggplot(DT, aes(x=x, y=y.0.05, col=z)) + geom_line()

fig1