2017-07-14 16 views
0

私はちょっとしたコードがついています。もちろん、私のジレンマを並べ替えるコードを読んでいただければ幸いですが、それをどのように並べ替えるかのヒントにも感謝しています。ここでRスタジオで1時間ごとのデータポイント(1日1回)と1時間ごとのポイント(24日)をプロットする

が行く:すべての まず、私はパッケージ(ggplot2、lubridate、およびopenxlsx)

に関連する部分をインストール: 私はイタリアガスTSOのWebサイトからファイルを抽出します。

Storico_G1 <- read.xlsx(xlsxFile = "http://www.snamretegas.it/repository/file/Info-storiche-qta-gas-trasportato/dati_operativi/2017/DatiOperativi_2017-IT.xlsx",sheet = "Storico_G+1", startRow = 1, colNames = TRUE) 

​​

を次に時刻の形式を変更します:

は、それから私は、私は維持したい変数を持つデータフレームを作成し

Storico_G1_df$pubblicazione <- ymd_h(Storico_G1_df$Storico_G1.pubblicazione) 

今、闘争が始まります。この例では、範囲が非常に異なるため、2つの異なるY軸を使用して2つの時系列をグラフ化したいと思います。これは実際には問題ではありません。なぜなら、溶融関数とggplotを使って、それを達成できるからです。しかし、1列にはNAsが存在するため、どのように回避できるかはわかりません。不完全な(SAS)欄では主に16時にデータポイントを気にするので、私は理想的には1つのチャートに時間プロットを、2番目のチャートには1日に1データポイント(16:00と言う)を持つことになります。私は意味のないチャートスタイルの無関係な写真を添付し​​ました。しかし、添付のチャートでは、両方のチャートに同じように多くのデータポイントがあるため、正常に動作します。任意のヒントに感謝

enter image description here

世話

答えて

0
library(lubridate) 
library(ggplot2) 
library(openxlsx) 
library(dplyr) 

#Use na.strings it looks like NAs can have many values in the dataset 
storico.xl <- read.xlsx(xlsxFile = "http://www.snamretegas.it/repository/file/Info-storiche-qta-gas-trasportato/dati_operativi/2017/DatiOperativi_2017-IT.xlsx", 
         sheet = "Storico_G+1", startRow = 1, 
         colNames = TRUE, 
         na.strings = c("NA","N.D.","N.D")) 

#Select and rename the crazy column names 
storico.g1 <- data.frame(storico.xl) %>% 
    select(pubblicazione, IMMESSO, SBILANCIAMENTO.ATTESO.DEL.SISTEMA..SAS.) 
names(storico.g1) <- c("date_hour","immesso","sads") 


# the date column look is in the format ymd_h 
storico.g1 <- storico.g1 %>% mutate(date_hour = ymd_h(date_hour)) 


#Not sure exactly what you want to plot, but here is each point by hour 
ggplot(storico.g1, aes(x= date_hour, y = immesso)) + geom_line() 

#For each day you can group, need to format the date_hour for a day 
#You can check there are 24 points per day 
#feed the new columns into the gplot 

storico.g1 %>% 
    group_by(date = as.Date(date_hour, "d-%B-%y-")) %>% 
    summarise(count = n(), 
      daily.immesso = sum(immesso)) %>% 
    ggplot(aes(x = date, y = daily.immesso)) + geom_line() 
+0

はあなたの助けをありがとう!私の難しさは、頻度の低いデータ(1日に24時間のデータポイント)と、まれなデータ(1日に16時のデータポイントを1日に1回フィルタリングする場合)を一緒にプロットしたいということです。私はヒントを見落とした場合、私は事前に謝罪します.. –

関連する問題