data <- structure(c(-0.447315711911355, 0.670646511357067, 0.28805337765816,
0.210323243582978, 0.558951367403988, 0.607248748494035, -1.16412611819213,
0.0915424491269807, 0.469191549286902, -0.619038988584179, -0.659390830669932,
-0.924810741449363, -1.42269762267215, -0.13593956988495, -1.92882493234572,
-1.27638233136087, 1.3816213467106, 0.365757310517179, -0.479538532782686,
0.70769126786196, -0.326429694012458, -1.01751602957572, 0.555459246627799,
-0.355015029145993, -0.065915904785214, 0.576685372310354, 1.08050319208107,
-0.697995949639672, 0.661562203593662, 0.0968130184654234, -0.672212026424006,
0.0269233940788362, 0.661236459007207, -0.507557327616088, -0.800274398837844,
1.93302333485735, -1.28135392022731, 1.33095400120017, -0.377753506417346,
0.700663669871313, -1.08566228220391, -1.08906574084574, -1.04577335310861,
0.956870855865283, -2.21389083133313, 0.299118475920725, 0.523434618906021,
0.0428254530914905, 0.443157396704438, 2.00841231202171), .Dim = c(10L,
5L), .Dimnames = list(NULL, c("Return1", "Return2", "Return3",
"Return4", "Return5")))
您可以使用简单的 hist 函数将所有内容组合在一起
par(mfrow=c(1,5))
hist(data[,1])
hist(data[,2])
hist(data[,3])
hist(data[,4])
hist(data[,5])
你可以使用 gplot
你需要按如下方式安装一个包
install.packages("gridExtra")
注意:
不要忘记加载库和
添加任何需要的包或库
p1<- qplot(data[,1], binwidth=.5)
p2<- qplot(data[,2], binwidth=.5)
p3<- qplot(data[,3], binwidth=.5)
p4<- qplot(data[,4], binwidth=.5)
p5<- qplot(data[,5], binwidth=.5)
grid.arrange(p1, p2, p3, p4,p5, ncol=2)
或者你可以使用ggplot如下:
row.names (data) <- NULL
df<- as.data.frame(data)
p1<- ggplot(df, aes(df[,1])) + geom_histogram(binwidth=.5)
p2<- ggplot(df, aes(df[,2])) + geom_histogram(binwidth=.5)
p3<- ggplot(df, aes(df[,3])) + geom_histogram(binwidth=.5)
p4<- ggplot(df, aes(df[,4])) + geom_histogram(binwidth=.5)
p5<- ggplot(df, aes(df[,5])) + geom_histogram(binwidth=.5)
grid.arrange(p1, p2, p3, p4,p5, ncol=2)