简体   繁体   English

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

[英]R: visualizing multiple sets of data on same plot

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"

I have 2 sets of data, power_1 and power_2 . 我有2组数据, power_1power_2 I would like to plot them on the same graph with the first column on the x-axis and the second column on the y-axis. 我想将它们绘制在同一图上,第一列在x轴上,第二列在y轴上。 I was trying to combine the two data sets (say, by rbind ), but this didn't work since they are of class SKAT_Power . 我试图合并这两个数据集(例如,由rbind ),但这没有用,因为它们属于SKAT_Power类。 How can I plot these data? 如何绘制这些数据?

I did it using data.table and ggplot2 : 我使用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()

图。1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM