Reputation: 29
I am using this code, and I can get the qqplot for each column of my data. However, I do not know how to combine the qqplots
together by facet_wrap
with ggplot2
The data
> head(X)
V1 V2 V3 V4 V5
1 1 1889 1651 1561 1778
2 2 2493 2048 2087 2197
3 3 2119 1700 1815 2222
4 4 1645 1627 1110 1533
5 5 1976 1916 1614 1883
6 6 1712 1712 1439 1546
I need to to do a qqplot for V2,V3,V4,V5 I am using this code for each variable
q1<-qqnorm(X$V2, pch = 20, main="QQPlot for V2")
Also I can do it by this
ggplot(X, aes(sample = V2)) +stat_qq() + stat_qq_line()
I do not know how to use facet in ggplot2 to combine all the qqplots
Upvotes: 0
Views: 387
Reputation: 81713
You can use stack
to transform the data into the long format.
X2 <- stack(X)
ggplot(X2, aes(sample = values)) +
stat_qq() +
stat_qq_line() +
facet_wrap( ~ ind)
Upvotes: 3