0
structure(list(Team = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L), .Label = "Union", class = "factor"), Date = structure(c(1L, 
1L, 1L, 2L, 2L, 2L, 4L, 3L, 3L, 4L, 3L, 3L, 5L, 3L, 3L, 6L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 6L, 3L, 3L, 3L, 3L, 3L, 3L, 6L, 6L, 6L, 
6L, 3L, 7L, 8L, 9L, 10L, 10L), .Label = c("2012-01-06", "2012-02-06", 
"2012-03-06", "2012-04-06", "2012-05-06", "2012-07-06", "2012-09-06", 
"2012-10-06", "2012-11-06", "2012-12-06"), class = "factor"), 
    STime = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L
    ), .Label = "07:03", class = "factor"), ETime = structure(c(6L, 
    7L, 8L, 5L, 5L, 1L, 2L, 3L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 11L, 
    10L, 9L, 8L, 10L, 7L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
    5L, 5L, 5L, 5L, 5L, 4L, 5L, 5L, 5L, 5L), .Label = c("01:13", 
    "03:13", "06:13", "09:13", "10:13", "11:13", "12:13", "13:13", 
    "15:13", "16:13", "18:13"), class = "factor")), .Names = c("Team", 
"Date", "STime", "ETime"), class = "data.frame", row.names = c(NA, 
-40L))

私はこれをやっています:

ggplot(df, aes(Date, ETime, group="Team")) + geom_point(size=0.3) + facet_wrap(~ Team)

y 軸を 00:00 から 23:29 まで 2 時間刻みで表示したいと思います。機能していないscale_y_continousを試しました。助言がありますか?

4

1 に答える 1

2

日付と時刻の列を POSIXt 形式のデータに変更することをお勧めします。次に、軸を変更すると、ラベル付けが簡単になります。現在、日付と時刻は要素として保存されています。

library(ggplot2)

# Change relevant columns from 'factor' to 'POSIXt'.
df$ETime = strptime(as.character(df$ETime), "%H:%M")
df$Date = strptime(as.character(df$Date), "%Y-%m-%d")

plot_1 = ggplot(df, aes(x=Date, y=ETime)) +
         geom_point() +
         labs(title="Plot 1")

# Manually set datetime limits and breaks.
y_limits = as.POSIXct(c(strptime("00:00", "%H:%M"), strptime("23:29", "%H:%M")))
y_breaks = seq(from=strptime("00:00", "%H:%M"), 
                 to=strptime("23:29", "%H:%M"), by="2 hours")
y_labels = format(y_breaks, "%H:%M")

plot_2 = ggplot(df, aes(x=Date, y=ETime)) + 
         geom_point() + 
         scale_y_datetime(limits=y_limits, breaks=y_breaks, labels=y_labels) +
         labs(title="Plot 2")

library(gridExtra)

png("plots.png", width=8, height=4, units="in", res=120)
grid.arrange(plot_1, plot_2, nrow=1)
dev.off()

ここに画像の説明を入力

于 2013-01-09T03:04:45.943 に答える