我有一个3d数组可以使用像ggplot2这样的库来获得1个图形,其中x维度是我的数组的第一个元素(100,200,300),其中y维度是我的第二个元素数组(3,4,5)。然后绘图的线条是我的数组的第三个元素。所以我最终得到了3行0.025,0.05,0.075的线图。
数组:
test <- structure(c(0.375273574511523, 0.333640287506392, 0.349192797931677,
0.337219826870885, 0.318182584380369, 0.320214135918515, 0.361795340513871,
0.303301639079779, 0.308995818880145, 0.486614010203226, 0.491666372158188,
0.450500424965387, 0.464697136076233, 0.467426609239434, 0.475098558417684,
0.467056879901411, 0.43139438188378, 0.452656403568038, 0.451463478297646,
0.516198183913922, 0.522289371444439, 0.499669539425807, 0.527507832814278,
0.529443687671795, 0.520999085947043, 0.526833049499385, 0.533862568866946
), .Dim = c(3L, 3L, 3L), .Dimnames = list(c("100", "200", "300"
), c("3", "4", "5"), c("0.025", "0.05", "0.075")))
> test
, , 0.025
3 4 5
100 0.3752736 0.3372198 0.3617953
200 0.3336403 0.3181826 0.3033016
300 0.3491928 0.3202141 0.3089958
, , 0.05
3 4 5
100 0.4866140 0.4646971 0.4670569
200 0.4916664 0.4674266 0.4313944
300 0.4505004 0.4750986 0.4526564
, , 0.075
3 4 5
100 0.4514635 0.4996695 0.5209991
200 0.5161982 0.5275078 0.5268330
300 0.5222894 0.5294437 0.5338626
答案 0 :(得分:2)
将数组修改为数据框:
test2 <- adply(test, c(1,2,3))
对于绘图部分,我冒昧地重新解释你可能想做的事情。请注意,包含值本身,您将需要四个“维度”。
library(ggplot2)
ggplot( data=test2 ) + geom_line( aes(x=X1 , y=V1 , group= X3, colour = factor(X3))) +
facet_grid(.~X2)
答案 1 :(得分:1)