2017-06-14 8 views
1

XとY軸上の日付と時系列グラフは:Image of a line graph with date and month on the Y axis and the year on the X axis. All points on the graph are connected by a single line.プロット私は次のグラフを再現するためにRを使用しています

は、だから私は、次のデータフレームを使用

Doy = as.data.frame(list(Year=Year, M_Day =M_Day, Mon_day = Mon_day)) 

どこ年、M_DayとMon_dayは

Year = c(1960, 1961, 
    1962, 
    1963, 
    1964, 
    1965, 
    1966, 
    1967, 
    1968, 
    1969, 
    1970, 
    1971, 
    1972, 
    1973, 
    1974, 
    1975, 
    1976, 
    1977, 
    1978, 
    1979 
) 

M_Day = c("05-14", 
    "05-05", 
    "05-15", 
    "05-31", 
    "05-01", 
    "05-01", 
    "05-01", 
    "05-01", 
    "05-01", 
    "05-01", 
    "05-16", 
    "05-14", 
    "05-09", 
    "05-22", 
    "05-18", 
    "06-17", 
    "05-03", 
    "05-06", 
    "05-01", 
    "05-03") 

Mon_day = c("May-14", 
    "May-05", 
    "May-15", 
    "May-31", 
    "May-01", 
    "May-01", 
    "May-01", 
    "May-01", 
    "May-01", 
    "May-01", 
    "May-16", 
    "May-14", 
    "May-09", 
    "May-22", 
    "May-18", 
    "Jun-17", 
    "May-03", 
    "May-06", 
    "May-01", 
    "May-03") 

とggplot2

から以下の2つのコマンド以下の通りです。私の最初のグラフに似ていない、次の Image of two graphs both of which have the date and month on the Y axis and the year on the X axis. Only the points with the same Y value are connected so there are multiple lines on the graph and some points aren't connected by a line at all.

を与える

答えて

0

スケールで日付の所望の出力フォーマットを指定as.Date(M_Day, format="%m-%d")を使用して、日付形式に日付を変換します

Year <- 1960:1979 

M_Day <- as.Date(x=c("05-14", "05-05", "05-15", "05-31", "05-01", "05-01", "05-01", "05-01", "05-01", "05-01", "05-16", "05-14", "05-09", "05-22", "05-18", "06-17", "05-03", "05-06", "05-01", "05-03"), 
       format="%m-%d") 

Doy <- data.frame(Year=Year, M_Day=M_Day) 

ggplot(Doy) + geom_line(aes(x=Year, y=M_Day), col="darkblue") + 
    geom_point(aes(x=Year, y=M_Day), col="darkred") + 
    scale_y_date(date_breaks = "1 week", date_labels = "%d %b") 
+0

どうもありがとうございましたmzubaを、これは私が:) :)まさに必要です。 – Andy

関連する問題