はこれを試してみてください。
ts1 <- rnorm(100) # randomly generated values for times series
ts2 <- rnorm(100)
ts3 <- rnorm(100)
ts4 <- rnorm(100)
library(TTR)
df <- data.frame(time=rep(1:100, 8),
id=as.factor(rep(1:8, each=100)), id1=as.factor(rep(1:4, each=200)),
type=as.factor(rep(rep(1:2, each=100),4)),
value=c(ts1, SMA(ts1), ts2, SMA(ts2), ts3, SMA(ts3), ts4, SMA(ts4)))
library(ggplot2)
ggplot(df, aes(time, value, col=type, group=id)) +
geom_line() + facet_wrap(~id1, ncol=1) +
scale_color_manual(values=c('green', 'red'))+
guides(color=FALSE) + theme_bw() + theme(strip.text = element_blank())
はあなたが面ごとに異なるyのラベルをしたい場合は、これを試してください:なぜ質問は
library(grid)
library(gridExtra)
grid.arrange(ggplot(data.frame(time=rep(1:100, 2), id=as.factor(rep(1:2, each=100)),
type=as.factor(rep(1:2, each=100)),
ts1=c(ts1, SMA(ts1))), aes(time, ts1, col=type, group=id)) +
geom_line() + scale_color_manual(values=c('green', 'red')) + guides(color=FALSE) +
theme_bw() + theme(axis.text.x = element_blank(), axis.ticks = element_blank()) + xlab(''),
ggplot(data.frame(time=rep(1:100, 2), id=as.factor(rep(1:2, each=100)),
type=as.factor(rep(1:2, each=100)),
ts2=c(ts2, SMA(ts2))), aes(time, ts2, col=type, group=id)) +
geom_line() + scale_color_manual(values=c('green', 'red')) + guides(color=FALSE) +
theme_bw() + theme(axis.text.x = element_blank(), axis.ticks = element_blank()) + xlab(''),
ggplot(data.frame(time=rep(1:100, 2), id=as.factor(rep(1:2, each=100)),
type=as.factor(rep(1:2, each=100)),
ts3=c(ts3, SMA(ts3))), aes(time, ts3, col=type, group=id)) +
geom_line() + scale_color_manual(values=c('green', 'red')) + guides(color=FALSE) +
theme_bw() + theme(axis.text.x = element_blank(), axis.ticks = element_blank()) + xlab(''),
ggplot(data.frame(time=rep(1:100, 2), id=as.factor(rep(1:2, each=100)),
type=as.factor(rep(1:2, each=100)),
ts4=c(ts4, SMA(ts4))), aes(time, ts4, col=type, group=id)) +
geom_line() + scale_color_manual(values=c('green', 'red')) + guides(color=FALSE) + theme_bw(), ncol=1)
をdownvotedされますか? ? – Vini
ベースRで、x軸ラベルまたは 'plot(1:10、1:10、xlab =" "、xaxt =" n ")を削除するには' plot(1:10、1:10、xlab = "" ) 'を押して、ラベルとティックマークのラベルを削除します。 – lmo
ラベルとX軸のインデクシングを削除することができます。しかし、私は1つのグラフとして4つのプロットを一緒に得ることができません – Vini