[R] plot.ts error: cannot plot more than 10 series

Gabor Grothendieck ggrothendieck at gmail.com
Sun May 13 13:58:19 CEST 2012


On Sun, May 13, 2012 at 5:02 AM, Suhaila Haji Mohd Hussin
<bell_beauty12 at hotmail.com> wrote:
>
> Hello.
> I'm doing Principal Component Analysis. So I'm trying to plot the new data as time series like this:
> plot.ts(pr2$x)
> But it gives me error: Error in plotts(x = x, y = y, plot.type = plot.type, xy.labels = xy.labels,  :  cannot plot more than 10 series as "multiple"
> Here's my data dput it's really long so I just put in some essential information only for you to see:
> structure(list(sdev = c(163.444257295666, 104.206376841326, 97.9593394161277, 85.13008012602, 78.672940030061, 73.7044913582009, 68.9919940515061, 66.4914391167912, 63.5364862493486, 53.0067010985736, 50.3850160673695, 41.0505058921616, 36.6847894205371, 34.4922997539369, 32.8160496561452), rotation = structure(c(-0.341624025780871, -0.465361625382171, -0.254733743609541, -0.501601736275946, -0.32909803586058, 0.10346905261603, 0.0826920791661065, 0.04180674828032, 0.0317514777236264, -0.041673145049323, 0.00552096153263742, 0.302880866160923, 0.0611515661970536, -0.19666860832608, -0.0512002313448844, 0.0532192307778435, -0.279691445123637, -0.0330375822617488, 0.0296862808186525, 0.00754185914289494, -0.0483037204914515, -0.145633004945105, 0.0663131380872606, ...................................0.018728860610997, -0.867607192081349, -0.00746836023138116, -0.197845760644588, 0.354006015245109, -0.0234568336704251, 0.17996661095123, 0.0910352921083386, 0.118413710329641), .D!
>  im = c(20L, 15L), .Dimnames = list(    c("er", "pr", "ar", "l1", "l2", "b1", "b2", "h1", "h2", "h3",     "p1", "p2", "o1", "o2", "o3", "o4", "o5", "o6", "o7", "o8"    ), c("PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8",     "PC9", "PC10", "PC11", "PC12", "PC13", "PC14", "PC15"))),     center = structure(c(94.4986072423398, 94.9637883008357,     71.1838440111421, 179.793871866295, 180.57938718663, 12.6490250696379,     10.5292479108635, 10.8690807799443, 38.2479108635098, 137.543175487465,     0.612813370473538, 45.150417827298, 10.5459610027855, 91.3259052924791,     116.885793871866, 59.0055710306407, 172.598885793872, 14.3676880222841,     5.0974930362117, 3.8857938718663), .Names = c("er", "pr",     "ar", "l1", "l2", "b1", "b2", "h1", "h2", "h3", "p1", "p2",     "o1", "o2", "o3", "o4", "o5", "o6", "o7", "o8")), scale = FALSE,     x = structure(c(-38.7640736739586, -85.3987965131485, 279.953119866405,     121.49850702536, 348.387859356463, -149.756720052989, 114.1!
>  99587790773,     -258.129158201887, 245.434330475019, -74.518625315929
> , 114.858457403311,     246.989390591038, 264.221327740388, -59.7706080070487, -66.9519268984565,     -202.267758377027, -61.2743296889704, -63.3534745591336, .................................................
> 403375504553, 41.2280423622485,     78.1688899057297, -17.9229807680497, 1.892930692659, -0.121464277679548,     -10.9161618391865, 9.77739319210259, -30.4117535843182), .Dim = c(359L,     15L), .Dimnames = list(c("9", "12", "13", "14", "18", "22",     "24", "29", "30", "31", "32", "33", "34", "44", "49", "53",     "54", "58", "59", "60", "62", "66", "69", "70", "75", "76",     "80", "87", "88", "93", "94", "96", "100", "101", "102",     "106", "114", "115", "116", "126", "128", "129", "131", "133",     "135", "137", "139", "141", "142", "144", "147", "151", "154",     "157", "158", "160", "161", "164", "169", "170", "171", "175",     "179", "180", "181", "186", "193", "195", "200", "205", "206",     "209", "218", "220", "221", "222", "224", "225", "226", "228",     "231", "232", "233", "235", "239", "243", "244", "253", "256",     "260", "264", "265", "266", "268", "269", "272", "275", "280", .........................................................   "1025", "1032", "1033"!
>  , "1035", "1036", "1038", "1039", "1041",     "1042", "1046", "1047", "1048", "1051", "1055", "1059", "1060",     "1064", "1072", "1076"), c("PC1", "PC2", "PC3", "PC4", "PC5",     "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13",     "PC14", "PC15")))), .Names = c("sdev", "rotation", "center", "scale", "x"), class = "prcomp")
> Please help,Suhaila


The dput output seems to have gotten messed up in transmission so lets
use an artificial example:

set.seed(123)
DF <- as.data.frame(matrix(rnorm(600), nc = 12)) # 12 columns
p <- prcomp(DF)

# error - cannot plot more than 10
plot.ts(p$x)

# try it several ways with plot.zoo

library(zoo)
plot(as.zoo(p$x)) # ok

# or - all on one panel

k <- ncol(p$x)
plot(as.zoo(p$x), screen = 1, col = 1:k)

# or - 1st two on 1st panel, 2nd two on 2nd panel, etc.

plot(as.zoo(p$x), screen = seq(0, len = k) %/% 2, col = 1:2)

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list