2017-08-31 11 views
0

ヒートマップのようなプロットで時系列データを入力しようとしています。私は下の例を取り除きました。私は "大きな"データブロブについてお詫びしますが、私はより多くの人工的な例でそれを再現することができませんでした。x軸上のデータブレークは、startの代わりにendの終わりに表示されます

問題は、この例ではデータが28番目から30番目に移動していることです。しかしプロットでは、27日から29日までのデータがあると思うでしょう。 休憩は、当然のことではなく、終わりに行われます。

ブレークを手動で設定すると思っていたものを試しましたが、配置場所は変わりません。

代わりに表示される日付が29日と30日になるように変更するにはどうすればよいですか?

DATA:

data <- structure(list(time_run = structure(c(1503968136, 1503938008, 
1503962343, 1503956548, 1503917153, 1504059128, 1504011336, 1504078913, 
1503915993, 1503968136, 1503938008, 1503962343, 1503956548, 1503917153, 
1504059128, 1504011336, 1504078913, 1503915993, 1503968136, 1503938008, 
1503962343, 1503956548, 1503917153, 1504059128, 1504011336, 1504078913, 
1503915993, 1503968136, 1503938008, 1503962343, 1503956548, 1503917153, 
1504059128, 1504011336, 1504078913, 1503915993, 1503968136, 1503938008, 
1503962343, 1503956548, 1503917153, 1504059128, 1504011336, 1504078913, 
1503915993, 1503968136, 1503938008, 1503962343, 1503956548, 1503917153, 
1504059128, 1504011336, 1504078913, 1503915993, 1503968136, 1503938008, 
1503962343, 1503956548, 1503917153, 1504059128, 1504011336, 1504078913, 
1503915993, 1503968136, 1503938008, 1503962343, 1503956548, 1503917153, 
1504059128, 1504011336, 1504078913, 1503915993, 1503968136, 1503938008, 
1503962343, 1503956548, 1503917153, 1504059128, 1504011336, 1504078913, 
1503915993, 1503968136, 1503938008, 1503962343, 1503956548, 1503917153, 
1504059128, 1504011336, 1504078913, 1503915993, 1503968136, 1503938008, 
1503962343, 1503956548, 1503917153, 1504059128, 1504011336, 1504078913, 
1503915993, 1503968136, 1503938008, 1503962343, 1503956548, 1503917153, 
1504059128, 1504011336, 1504078913, 1503915993), class = c("POSIXct", 
"POSIXt"), tzone = "Europe/Paris"), x_text = c("NMP (17)", "NMP (17)", 
"NMP (17)", "NMP (17)", "NMP (17)", "NMP (17)", "NMP (17)", "NMP (17)", 
"NMP (17)", "TEA (22)", "TEA (22)", "TEA (22)", "TEA (22)", "TEA (22)", 
"TEA (22)", "TEA (22)", "TEA (22)", "TEA (22)", "ACN (23)", "ACN (23)", 
"ACN (23)", "ACN (23)", "ACN (23)", "ACN (23)", "ACN (23)", "ACN (23)", 
"ACN (23)", "Acetonitrile/Dimethylformamide (29)", "Acetonitrile/Dimethylformamide (29)", 
"Acetonitrile/Dimethylformamide (29)", "Acetonitrile/Dimethylformamide (29)", 
"Acetonitrile/Dimethylformamide (29)", "Acetonitrile/Dimethylformamide (29)", 
"Acetonitrile/Dimethylformamide (29)", "Acetonitrile/Dimethylformamide (29)", 
"Acetonitrile/Dimethylformamide (29)", "DMAP (33)", "DMAP (33)", 
"DMAP (33)", "DMAP (33)", "DMAP (33)", "DMAP (33)", "DMAP (33)", 
"DMAP (33)", "DMAP (33)", "DIPEA (36)", "DIPEA (36)", "DIPEA (36)", 
"DIPEA (36)", "DIPEA (36)", "DIPEA (36)", "DIPEA (36)", "DIPEA (36)", 
"DIPEA (36)", "TPA (42)", "TPA (42)", "TPA (42)", "TPA (42)", 
"TPA (42)", "TPA (42)", "TPA (42)", "TPA (42)", "TPA (42)", "ACN (43)", 
"ACN (43)", "ACN (43)", "ACN (43)", "ACN (43)", "ACN (43)", "ACN (43)", 
"ACN (43)", "ACN (43)", "ACN (46)", "ACN (46)", "ACN (46)", "ACN (46)", 
"ACN (46)", "ACN (46)", "ACN (46)", "ACN (46)", "ACN (46)", "Acetonitrile/Methanol (47)", 
"Acetonitrile/Methanol (47)", "Acetonitrile/Methanol (47)", "Acetonitrile/Methanol (47)", 
"Acetonitrile/Methanol (47)", "Acetonitrile/Methanol (47)", "Acetonitrile/Methanol (47)", 
"Acetonitrile/Methanol (47)", "Acetonitrile/Methanol (47)", "Pthalic Anhydride (48)", 
"Pthalic Anhydride (48)", "Pthalic Anhydride (48)", "Pthalic Anhydride (48)", 
"Pthalic Anhydride (48)", "Pthalic Anhydride (48)", "Pthalic Anhydride (48)", 
"Pthalic Anhydride (48)", "Pthalic Anhydride (48)", "ACN (26)", 
"ACN (26)", "ACN (26)", "ACN (26)", "ACN (26)", "ACN (26)", "ACN (26)", 
"ACN (26)", "ACN (26)"), c_ord = c(24L, 24L, 24L, 24L, 24L, 24L, 
24L, 24L, 24L, 82L, 82L, 82L, 82L, 82L, 82L, 82L, 82L, 82L, 29L, 
29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 19L, 19L, 19L, 19L, 19L, 
19L, 19L, 19L, 19L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 
85L, 85L, 85L, 85L, 85L, 85L, 85L, 85L, 85L, 27L, 27L, 27L, 27L, 
27L, 27L, 27L, 27L, 27L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 
31L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 50L, 50L, 50L, 
50L, 50L, 50L, 50L, 50L, 50L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 
17L, 17L, 44L, 44L, 44L, 44L, 44L, 44L, 44L, 44L, 44L), value = c(9837.2490234375, 
9145.20068359375, 8794.9443359375, 8782.52001953125, 10083.5, 
9837.2900390625, 8973.68896484375, 8972.79248046875, 10112.3569335938, 
3006.42431640625, 2483.09973144531, 2297.7724609375, 2388.14697265625, 
3180.48327636719, 2907.27026367188, 2407.63500976562, 2381.24938964844, 
3600.30932617188, 809.412658691406, 790.167205810547, 698.132263183594, 
715.636016845703, 1123.26507568359, 728.464904785156, 653.518646240234, 
581.541839599609, 1139.99267578125, 1109.13757324219, 1007.88500976562, 
960.396789550781, 992.408813476562, 1136.28955078125, 1090.0615234375, 
1000.72674560547, 963.919616699219, 1155.56555175781, 2972.392578125, 
3045.79138183594, 2519.54443359375, 2830.70581054688, 4292.25, 
2794.20654296875, 2464.75134277344, 2213.01623535156, 3474.59985351562, 
6243.59130859375, 5039.56372070312, 4662.6640625, 4833.80029296875, 
6457.42724609375, 6183.39208984375, 5053.65649414062, 4982.33056640625, 
7820.1474609375, 569.280151367188, 525.962310791016, NA, NA, 
568.004791259766, 568.837036132812, 526.013427734375, 529.354675292969, 
601.071899414062, 6509.4921875, 5798.27709960938, 5015.94189453125, 
5225.66235351562, 8109.38256835938, 5580.72314453125, 4410.88842773438, 
3981.27697753906, 8123.06518554688, 3046.7998046875, 2847.50915527344, 
2434.40698242188, 2575.9501953125, 3872.27795410156, 2554.265625, 
2210.39123535156, 2017.80932617188, 3846.21325683594, 720.536865234375, 
744.396423339844, 743.815673828125, 683.698913574219, 800.720550537109, 
693.875, 719.847290039062, 708.015197753906, 767.747467041016, 
10337.0947265625, 9417.3125, 9031.552734375, 9194.966796875, 
10259.4594726562, 10270.6875, 9491.2001953125, 9433.85546875, 
10691.4228515625, NA, NA, NA, NA, 551.797607421875, NA, NA, NA, 
547.68701171875)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-108L), .Names = c("time_run", "x_text", "c_ord", "value")) 

CODE:

library(ggplot2) 
library(scales) 


    p <- ggplot(data=data, aes(x=time_run, y = reorder(x_text, c_ord), fill=log10(value))) + 
     geom_tile() + 
     scale_x_datetime(labels = date_format("%Y-%m-%d"), breaks=date_breaks("day")) + 
     theme_classic() + 
     theme(axis.text.x = element_text(angle=30, hjust = 1)) + 
     theme(panel.background=element_rect(fill="lightgrey", colour="lightgrey")) 


     p 

enter image description here

sort(unique(data$time_run)) 

[1] "2017-08-28 12:26:33 CEST" "2017-08-28 12:45:53 CEST" "2017-08-28 18:33:28 CEST" "2017-08-28 23:42:28 CEST" "2017-08-29 01:19:03 CEST" 
[6] "2017-08-29 02:55:36 CEST" "2017-08-29 14:55:36 CEST" "2017-08-30 04:12:08 CEST" "2017-08-30 09:41:53 CEST" 

答えて

2

)DATE_FORMAT(タイムゾーンの使用に起因すると思われます。タイムゾーン情報が含まれていない独自の書式機能を記述することができます。

my_date_format <- function (format = "%Y-%m-%d") { 
    function(x) format(x, format) 
} 

p <- ggplot(data=data, aes(x=time_run, y = reorder(x_text, c_ord), fill=log10(value))) + 
    geom_tile() + 
    scale_x_datetime(labels = my_date_format("%Y-%m-%d"), breaks=date_breaks("day")) + 
    theme_classic() + 
    theme(axis.text.x = element_text(angle=30, hjust = 1)) + 
    theme(panel.background=element_rect(fill="lightgrey", colour="lightgrey")) 


p 
+0

ありがとうございます!そのヒントに基づいて 'lubridate'を使って' labels = date_format( "%Y-%m-%d"、tz = tz(data $ time_run)) 'を実行することができます。プロット上の実際の配置はタイムゾーンの影響を受けていないようです。 –