嘗試此動物園的經典圖形,動物園點陣圖形和動物園GGPLOT2顯卡:
library(zoo)
z <- read.zoo(DT, split = 1, index = 2, FUN = identity)
Names <- read.table(text = names(z), sep = ".", col.names = c("screen", "col"))
plot(z, screen = Names$screen, col = Names$col) # also see note 3 below
library(lattice)
xyplot(z, screen = Names$screen, col = Names$col) # also see note 3 below
library(ggplot2) # also see note 4 below
m <- fortify(z, melt = TRUE)
m2 <- transform(m, screen = sub("\\..*", "", Series), col = sub(".*\\.", "", Series))
qplot(Index, Value, data = m2, col = col, geom = "line") + facet_wrap(~ screen)
注
1)如果我們只是想獨立的面板它只是是plot(z)
,xyplot(z)
和autoplot(z)
。
2)names(z)
和Names
是:
> names(z)
[1] "V1.a" "V2.a" "V1.b" "V2.b" "V1.c" "V2.c"
> Names
screen col
1 V1 a
2 V2 a
3 V1 b
4 V2 b
5 V1 c
6 V2 c
3)我們可能只是硬編碼它,因爲這(在這種情況下,我們就不需要Names
):
plot(z, screen = 1:2, col = c(1, 1, 2, 2, 3, 3))
xyplot(z, screen = 1:2, col = c(1, 1, 2, 2, 3, 3))
4)在這裏是不涉及z
的ggplot2替代方案。其轉換DT
長形式data.table包,然後執行qplot
:
long <- DT[, list(Series = names(.SD), Value = unlist(.SD)), by = list(type, time)]
qplot(time, Value, data = long, col = type, geom = "line") + facet_wrap(~ Series)
''read.zoo''中的'split'我可以繪製多列,但是我繪製了更多的繪製面板(2 * 3)我想(2)。 – JerseyGood
在每種情況下都進行了修改以生成2個面板。 –
@ G.Grothendieck優秀的回答!! + 1 – agstudy