2017-02-15 11 views
0

背景:各病院ベッドが空になる時間(患者の退院時)と新しい患者がベッドに置かれる時間を表示する必要があります。新しい患者のためのベッドを準備する。水平バープロット/ geom_segmentのタイムクラスデータのラベルを明確にする

プロットの目的:各部屋/ベッドに2つの水平バーがあります.1つは(現在はグレーで)退院している患者を示し、もう1人は同じ患者に配置された新しい患者を示していますベッド。

質問:x軸に時間を表示するにはどうすればよいですか? class = "times"データでの作業についてのドキュメントへの参照にも感謝します。小数として表示回数と

BedMap <- structure(list(
    Date = structure(c(17210, 17210, 17210, 17210, 17210, 17210, 17210), class = "Date"), 
    RoomBed = c("TestBed1", "TestBed2", "TestBed3", "TestBed4", "TestBed5", "TestBed6", "TestBed7"), 
    UnitGroup = c("Tele", "Tele", "2P", "2P", "3P", "Tele", "ICU"), 
    DcOrderTime = structure(c(0.358333333333333, 0.377777777777778, 0.430555555555556, 0.470833333333333, 0.395833333333333, 0.623611111111111, 0.441666666666667), 
         format = "h:m:s", class = "times"), 
    DcTime = structure(c(0.457638888888889, 0.475694444444444, 0.5, 0.59375, 0.625, 0.700694444444444, 0.770833333333333), 
       format = "h:m:s", class = "times"), 
    DecisionTime = structure(c(0.582638888888889, 0.539583333333333, 0.886111111111111, 0.596527777777778, 0.675, 0.653472222222222, 0.777777777777778), 
         format = "h:m:s", class = "times"), 
    RequestBedTime = structure(c(0.60625, 0.545138888888889, 0.91875, 0.84375, 0.707638888888889, 0.713888888888889, 0.857638888888889), 
         format = "h:m:s", class = "times"), 
    DepartTime = structure(c(0.629166666666667, 0.599305555555556, 0.974305555555556, 0.952083333333333, 0.859722222222222, 0.770138888888889, 0.910416666666667), 
        format = "h:m:s", class = "times")), 
    class = "data.frame", row.names = c(NA, -7L), 
    .Names = c("Date", "RoomBed", "UnitGroup", "DcOrderTime", "DcTime", "DecisionTime", "RequestBedTime", "DepartTime")) 

そして現在のプロット、::

サンプル・データ

enter image description here

ggplot(BedMap) + 
    geom_segment(aes(x = 0, #start of light grey bar, indicates bed occupied & discharge planning has not yet started 
       y = RoomBed, 
       xend = DcOrderTime, #end of light grey bar 
       yend = RoomBed), 
      color = "Light Grey", 
      size = 6) + 
    geom_segment(aes(x = DcOrderTime, #start of dark grey bar, indicates bed still occupied but discharge planning has begun 
       y = RoomBed, 
       xend = DcTime, #end of dark grey bar, indicates patient has been discharged, bed is unoccupied 
       yend = RoomBed), 
       color = "Dark Grey", 
       size = 6) + 
    geom_segment(aes(x = DepartTime, #start of blue bar, indicates new patient has been placed in bed 
       y = RoomBed, 
       xend = 1, #end of blue bar (set at midnight/end of day) 
       yend = RoomBed), 
       color = "Blue", 
       size = 6) + 
    geom_point(aes(x = DecisionTime, 
      y = RoomBed), 
     color = "black", size = 3) + 
    geom_point(aes(x = RequestBedTime, 
      y = RoomBed), 
     color = "green", size = 3) + 
    theme(legend.position = "none") + 
    labs(x = "Time", y = "Room-Bed", title = "Daily Bed Map") 

私はBedMap DFを表示すると、時間が(正しくフォーマット表示たとえば、DcOrderTimeは、「08:36:00」、「09:04:00」、「10:20:00」、「11:18:00」、「09:30:00」などと表示されます。しかし、x軸は10進数で表示されます。小数点を値を表示するようにマッピングすることなく、x軸を「時」クラスとして表示するためのプロットコードを伝える方法はありますか?

View(BedMap) 
+0

あなたの時間の値は?どのように表示したいですか?時間の値を必要な形式に変換する関数を記述し、次にhttp://stackoverflow.com/questions/11610377/how-do-i-change-the-formatting-of-numbers-on-anaxis- with-ggplotを使用する方法については、 –

+0

上記のように、現在のデータにView(BedMap)を使用すると、時刻値が時刻として表示されます。例:DcOrderTime < - c( "08:36:00"、 "09:04:00"、 "10 「20:00」、「11:18:00」、「09:30:00」、「14:58:00」、「10:36:00」)。私は軸の上にランダムなラベルをどのようにマップするかを知っていますが、データはすでに時間形式であるため、変換を行う必要はありません。軸がh:m:s形式で表示されるように指定する方法があると思いました。 – jesstme

+1

'times'クラスはどこに定義されていますか? –

答えて

1

問題は、私は(前にそれを使ったことがないた、私は実際にはクラスのドキュメントを見つけることができませんが)timesクラスは一日の時間ではなく、継続時間を保持するように見えるという事実にリンクされている、と思います、です。そのフォーマットはggplotによって明示的に処理されないので、プロットのためにnumericに変換されています(出力に格納されている数値をdputから見ることができます)。

POSIXに変換するか、値を直接時刻として保存する方が良い解決策がある可能性がありますが、numericの値(1日の端数)に24を掛けて時間。 scale_x_time

enter image description here

に組み込みを与える

ggplot(BedMap) + 
    geom_segment(aes(x = 0, #start of light grey bar, indicates bed occupied & discharge planning has not yet started 
        y = RoomBed, 
        xend = 24*DcOrderTime, #end of light grey bar 
        yend = RoomBed), 
       color = "Light Grey", 
       size = 6) + 
    geom_segment(aes(x = 24*DcOrderTime, #start of dark grey bar, indicates bed still occupied but discharge planning has begun 
        y = RoomBed, 
        xend = 24*DcTime, #end of dark grey bar, indicates patient has been discharged, bed is unoccupied 
        yend = RoomBed), 
       color = "Dark Grey", 
       size = 6) + 
    geom_segment(aes(x = 24*DepartTime, #start of blue bar, indicates new patient has been placed in bed 
        y = RoomBed, 
        xend = 24, #end of blue bar (set at midnight/end of day) 
        yend = RoomBed), 
       color = "Blue", 
       size = 6) + 
    geom_point(aes(x = 24*DecisionTime, 
       y = RoomBed), 
      color = "black", size = 3) + 
    geom_point(aes(x = 24*RequestBedTime, 
       y = RoomBed), 
      color = "green", size = 3) + 
    theme(legend.position = "none") + 
    labs(x = "Time", y = "Room-Bed", title = "Daily Bed Map") + 
    scale_x_continuous(breaks = seq(0, 24, 3) 
        , labels = sprintf("%02d:00",seq(0, 24, 3)) 
        ) 

ここで動作するように表示されず、それは何の一部です:そうは次のように続いて、賢明な軸の区切りを設定し、必要に応じてラベルを追加timesクラスが時間帯ではなく期間を保持していることがわかります。このフォーマットを頻繁に使用している場合は、繰り返し使用する独自の変換/スケール関数を作成することをお勧めします。

0

ありがとうございました!答えは、class = "times"がchronパッケージのものであるという事実にあります。私のプロットの終わりに単純な行を追加することによって、ディスプレイは追加のマッピングなしで簡単に変更されました。下の私のオリジナルコードと最後の行を見てください。

ggplot(BedMap) + 
    geom_segment(aes(x = 0, #start of light grey bar, indicates bed occupied & discharge planning has not yet started 
      y = RoomBed, 
      xend = DcOrderTime, #end of light grey bar 
      yend = RoomBed), 
     color = "Light Grey", size = 6) + 
    geom_segment(aes(x = DcOrderTime, #start of dark grey bar, indicates bed still occupied but discharge planning has begun 
      y = RoomBed, 
      xend = DcTime, #end of dark grey bar, indicates patient has been discharged, bed is unoccupied 
      yend = RoomBed), 
      color = "Dark Grey", size = 6) + 
    geom_segment(aes(x = DepartTime, #start of blue bar, indicates new patient has been placed in bed 
      y = RoomBed, 
      xend = 1, #end of blue bar (set at midnight/end of day) 
      yend = RoomBed), 
      color = "Blue", size = 6) + 
    geom_point(aes(x = DecisionTime, 
     y = RoomBed), 
    color = "black", size = 3) + 
    geom_point(aes(x = RequestBedTime, 
     y = RoomBed), 
    color = "green", size = 3) + 
    theme(legend.position = "none") + 
    labs(x = "Time", y = "Room-Bed", title = "Daily Bed Map") + 
    scale_x_chron(format = "%H:%m", n = 12) 
関連する問題