2016-04-03 19 views
1

毎日午前7時から午後9時までの時系列データセットの傾向(Y)を調べるだけです。ggplot:日付に基づくファセットプロットの時間範囲を設定する

ggplotでプロットする方法を知っていますか?

ggplotファセットの各サブ図は、毎日午前7時から午後9時(2010/1/1から2010/1/14)までのトレンドYを示しています。

DateTime <- seq(as.POSIXct("2010/1/1 00:00"), as.POSIXct("2010/1/15 00:00"), "min") 
    Y <- rnorm(n=length(DateTime), mean=100, sd=1) 
    df <- data.frame(DateTime, Y) 

どうもありがとう:

は、ここに私のデータセットです!

答えて

3
require(ggplot2) 
df <- dplyr::filter(df, format(DateTime, '%H:%M:%S') < '09:00:00', format(DateTime, '%H:%M:%S') > '07:00:00') 

df$Day <- format(df$DateTime, '%d') 

plt <- ggplot(df, aes(DateTime, Y)) + geom_line() + facet_wrap(~Day, ncol = 2, scales = 'free_x') + 
theme(axis.text.x = element_text(size = rel(0.7))) 

print(plt) 

Output Image

+0

dplyr' 'からその' filter'ですか? – Axeman

+1

はい、申し訳ありませんが、私は言及していません。 – TheRimalaya

+0

私は今答えを修正しました。 – TheRimalaya

関連する問題