ggvis barchart使用日期作为x轴

时间:2015-06-25 23:59:17

标签: r ggvis

在处理闪亮的应用时,我一直在从ggplot切换到ggvis。我已经想了很多但是在条形图方面我真的很难过。我有一个日期和价值观的时间序列。我只是想要每个值的条形而不是点数(我希望能够绘制多个半透明条,如果有人在那里取得成功请分享)但是在这里我想让一个酒吧工作。

适用于layer_points()

df  %>% ggvis(~date, ~x) %>% layer_points() %>% scale_datetime("x")

不适用于layer_bars()

df  %>% ggvis(~date, ~x) %>% layer_bars() %>% scale_datetime("x")

我正在使用的数据......

structure(list(date = structure(c(7680, 7687, 7694, 7701, 7708, 
7715, 7722, 7729, 7736, 7743, 7750, 7757, 7764, 7771, 7778, 7785, 
7792, 7799, 7806, 7813, 7820, 7827, 7834, 7841, 7848, 7855, 7862, 
7869, 7876, 7883, 7890, 7897, 7904, 7911, 7918, 7925, 7932, 7939, 
7946, 7953, 7960, 7967, 7974, 7981, 7988, 7995, 8002, 8009, 8016, 
8023, 8030, 8037, 8044, 8051, 8058, 8065, 8072, 8079, 8086, 8093, 
8100, 8107, 8114, 8121, 8128, 8135, 8142, 8149, 8156, 8163, 8170, 
8177, 8184, 8191, 8198, 8205, 8212, 8219, 8226, 8233, 8240, 8247, 
8254, 8261, 8268, 8275, 8282, 8289, 8296, 8303, 8310, 8317, 8324, 
8331, 8338, 8345, 8352, 8359, 8366, 8373, 8380, 8387, 8394, 8401, 
8408, 8415, 8422, 8429, 8436, 8443, 8450, 8457, 8464, 8471, 8478, 
8485, 8492, 8499, 8506, 8513, 8520, 8527, 8534, 8541, 8548, 8555, 
8562, 8569, 8576, 8583, 8590, 8597, 8604, 8611, 8618, 8625, 8632, 
8639, 8646, 8653, 8660, 8667, 8674, 8681, 8688, 8695, 8702, 8709, 
8716, 8723, 8730, 8737, 8744, 8751, 8758, 8765, 8772, 8779, 8786, 
8793, 8800, 8807, 8814, 8821, 8828, 8835, 8842, 8849, 8856, 8863, 
8870, 8877, 8884, 8891, 8898, 8905, 8912, 8919, 8926, 8933, 8940, 
8947, 8954, 8961, 8968, 8975, 8982, 8989, 8996, 9003, 9010, 9017, 
9024, 9031, 9038, 9045, 9052, 9059, 9066, 9073), class = "Date"), 
    x = c(-0.034038302, 0.122310949, -0.002797319, 0.026515253, 
    0.039961798, 0.034473263, 0.00549937, -0.024125944, 0.000132490000000001, 
    0.011038357, -0.02135072, 0.030663311, -0.008915551, 0.004855042, 
    0.01563688, -0.007397493, 0.013569146, -0.004968811, -0.00250391, 
    0.014624532, 0.036937453, -0.023685917, 0.018921356, -0.003066779, 
    -0.009217771, 0.005317513, 0.010378968, 0.001580798, -0.015085972, 
    -0.000121644000000001, 0.020468644, 0.007925229, 0.007721276, 
    -0.003123545, -0.018317891, -0.014900591, 0.003260844, -0.001565358, 
    -0.014833886, 0.00366766, 0.014297139, -0.00725552, 0.012207931, 
    0.024035152, -0.024195095, -0.0043564, 0.000847468, 0.033031596, 
    0.023685033, 0.025143071, 0.046264348, 0.038285177, -0.009180356, 
    -0.01630399, -0.010131294, -0.009939386, -0.007620427, 0.013062259, 
    0.009912238, 0.000192973, -0.01683559, -0.002627549, 0.019836063, 
    -0.019946159, -0.020124331, 0.012921737, 0.034604405, -0.020774015, 
    0.00334805, 0.002271156, -0.018676732, 0.019160923, -0.01945997, 
    -0.014342636, -0.004867796, -0.010002446, -0.004372991, 0.023164369, 
    0.019824112, -0.00321832, -0.015785746, 0.040836652, 0.00148831, 
    0.012084485, -0.009603897, -0.004642148, -0.008399234, 0.010463218, 
    0.000256571000000001, -0.01978405, -0.003439498, -0.015669975, 
    0.026180724, 0.020373255, 0.019160773, 0.00692683, 0.010215506, 
    0.010861939, 0.012041143, 0.025734568, -0.004828156, 0.006914552, 
    -0.00720089, -0.000538489999999999, -0.008479448, 0.022926604, 
    0.002131842, -0.003688597, 0.025325639, -0.009562293, -0.024336741, 
    0.012907537, 0.004339383, 0.010744364, -0.013058765, -0.003672014, 
    -0.023887493, 0.01062259, 0.02088054, -0.035249878, -0.001462821, 
    0.01904368, -0.001308787, 0.009203217, 0.019856479, 0.011296979, 
    0.010039545, -0.01559142, 0.006083419, -0.017958978, -0.007488063, 
    0.01236649, -0.004459064, -0.004375386, 0.025500722, 0.005557851, 
    0.008444321, 0.002827649, 0.020320308, 0.031611803, -0.010199803, 
    -0.009425874, 0.007942729, -2.59379999999999e-05, 0.016669077, 
    -0.011666062, 0.022835386, -0.025599107, 0.013562535, -0.018365192, 
    0.018148786, 0.016649144, -0.009530455, 0.012996597, 0.002034778, 
    -0.005926478, -0.004897238, -0.004419719, 0.010848926, -0.006039757, 
    -0.030287605, 0.019221837, 0.001808161, -0.009566133, 0.005009292, 
    0.005365023, -0.004879922, -0.024637933, -0.0186584, 0.004786059, 
    -0.008245254, -0.000106243, -0.001714888, -0.017804006, -0.021200061, 
    0.003812757, 0.021940886, 0.002270448, -0.015417493, -0.045754612, 
    -0.003468442, -0.006242659, 0.022383824, -0.018753927, 0.008577571, 
    0.008655048, 0.02374636, 0.029522811, 0.009946946, 0.015419714, 
    -0.016714623, -0.014616188, 0.019670855, -0.038979063, 0.020491563, 
    -0.009640674, 0.046051144, -0.021434575, 0.000190443999999998, 
    -0.029013969), id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 
    12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 
    27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 
    42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 
    57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 
    72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 
    87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 
    101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 
    113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 
    125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 
    137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 
    149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 
    161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 
    173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 
    185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 
    197, 198, 199, 200)), .Names = c("date", "x", "id"), row.names = 53:252, class = "data.frame")

1 个答案:

答案 0 :(得分:-1)

将格式df$date设置为字符:

df$date <- as.character(df$date)

然后:

df  %>% ggvis(~date, ~x) %>% layer_bars()