4列を含むデータフレームがあります。qplotを使用して列1を列2に対して、列3を列4に対してプロットし、すべてのプロットを同じグラフに配置します。これを拡張して、20列のデータフレームを作成する必要があります。あなたが与えることができるどんな助けにも感謝します
編集以下は、私が使用しているデータフレームの例です。
1 2 3 4
1 0.01795918 0.9755562 0.02040816 0.05259072
2 0.04244898 0.9455753 0.03591837 0.03864464
3 0.05224490 0.9816900 0.06122449 0.03280435
4 0.07183673 0.9635419 0.08000000 0.03453257
5 0.09551020 0.9821122 0.10040816 0.03134642
6 0.12000000 0.9354895 0.11510204 0.03920271
7 0.13877551 0.9703654 0.13877551 0.03588973
8 0.16244898 0.9506424 0.15836735 0.03402917
9 0.17224490 0.9610043 0.18530612 0.03621932
10 0.20000000 0.9863483 0.19591837 0.03021983
11 0.22122449 0.9845782 0.22530612 0.03268187
12 0.22938776 0.9835922 0.22530612 0.03513692
....
一方を他方に対してプロットすることはできますが、それらすべてを1つのグラフにプロットする方法が必要です
df <- data.frame(A=runif(20), B=runif(20), C=runif(20), D=runif(20))
データをに再編成します
library(dplyr)
library(tidyr)
df1 <- df %>%
gather(key, value) %>% # convert everything into long format
mutate(grp = rep(1:(ncol(df)/2), each=(nrow(df)*2))) %>% # Each pairs of columns gets unique grouping value
mutate(index = rep(1:nrow(df), ncol(df))) %>% # Each observation in each group gets a unique value
mutate(key = rep(rep(c("x","y"), each=nrow(df)), ncol(df)/2)) %>% # label as x and y
spread(key, value) # convert to wide format again
grp index x y
1 1 1 0.4820801 0.47761962
2 1 2 0.5995658 0.86120948
3 1 3 0.4935413 0.43809711
4 1 4 0.1862176 0.24479728
5 1 5 0.8273733 0.07067905
# etc
NごとにN個のプロットfacet_wrap
を作成するために使用します grp
library(ggplot2)
ggplot(data=df1, aes(x=x, y=y)) +
geom_point() +
facet_wrap(~grp)
ggplot(data=df1, aes(x=x, y=y, colour=factor(grp))) +
geom_smooth()
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加