将小图中的y轴转换为时间标度

时间:2019-11-06 14:21:27

标签: r ggplot2 bar-chart yaxis

我正在为22位患者构建2种不同参数的条形图。

该数据库包括3列(用于患者姓名,参数 I 和参数 C )和数千行(每行对应达到每分钟其中一个参数( I C )的值,该值对应于22名患者之一。

因此,每代表每位患者 1分钟的监测

这是我的示例数据集的链接,该数据集包含4位患者的674行数据: https://docs.google.com/spreadsheets/d/1IP8yUh4zx6JfEr1DU4N0UWeMAbViVBk73ZolCNh1-Ks/edit?usp=sharing

问题是我需要x轴代表我的患者,并且需要 y轴来代表监测持续时间。由于每个数字都代表连续的分钟,因此我希望两个图表上的y轴的长度相同,比例相同。取而代之的是,我收到的I参数的y上限值为2000,C参数的y值为20000。

这是我的示例代码:

View(Maps)
colnames(Maps) <- c("Name","I","C")
I <- ggplot(Maps, aes(Name, I, fill=I))
#colors for I parameter
Icol <- c("green", "greenyellow", "#fed976","#feb24c", 
                     "#fd8d3c", "#fc4e2a", "#e31a1c", "#bd0026",
                     "#800026", "black")
#barplot
I + geom_bar(stat = "identity")+
            scale_fill_gradientn(colours = ICPcol,
                                                            limits = c(0,100), 
                                                            breaks = c(20, 40, 60, 80, 100), 
                                                            guide = guide_colourbar(nbin=100, 

                                                                                                                                        draw.ulim = FALSE, 
                                                                                                                                        draw.llim = FALSE))+
             guides(fill = guide_colourbar(barwidth = 1, barheight = 10))+
             coord_flip()+
             labs(x='patient', y='Monitoring duration', fill = "I mmHg")+
             theme(plot.background = element_blank(),
                              panel.grid.major = element_blank(),
                              panel.grid.minor = element_blank(),
                              panel.border = element_blank(),
                              panel.background = element_blank(),
                              axis.line = element_line(colour = "black"), 
                              axis.text.y = element_blank())

##Map if transform y axis in time scale with scale_y_time
I + geom_bar(stat = "identity")+
            scale_fill_gradientn(colours = ICPcol,
                                                            limits = c(0,100), 
                                                            breaks = c(20, 40, 60, 80, 100), 
                                                            guide = guide_colourbar(nbin=100, 
                                                                                                                                       draw.ulim = FALSE, 
                                                                                                                                       draw.llim = FALSE))+
            guides(fill = guide_colourbar(barwidth = 1, barheight = 10))+
            coord_flip()+
            scale_y_time()+
            labs(x='patient', y='Monitoring duration', fill = "I mmHg")+
            theme(plot.background = element_blank(),
                           panel.grid.major = element_blank(),
                            panel.grid.minor = element_blank(),
                            panel.border = element_blank(),
                            panel.background = element_blank(),
                            axis.line = element_line(colour = "black"), 
                            axis.text.y = element_blank())
###code for C parameter
C <- ggplot(Maps, aes(Name, C, fill=C))
Ccol <- c("black", "#bd0026","#e31a1c","#fd8d3c", "#dadaeb", 
                       "#bcbddc", "#9e9ac8", "#807dba", "#6a51a3", 
                      "#54278f", "#3f007d")
C + geom_bar(stat = "identity")+
            scale_fill_gradientn(colours = CPPcol,
                                                            limits = c(0,160), 
                                                            breaks = c(60, 120), 
                                                            guide = guide_colourbar(nbin=100,
                                                                                                                                       draw.ulim = FALSE, 
                                                                                                                                       draw.llim = FALSE))+
             guides(fill = guide_colourbar(barwidth = 1, barheight = 10))+
             coord_flip()+
             scale_y_time()+
             labs(x='patient', y='Monitoring duration', fill = "C mmHg")+
             theme(plot.background = element_blank(),
                                panel.grid.major = element_blank(),
                               panel.grid.minor = element_blank(),
                               panel.border = element_blank(),
                               panel.background = element_blank(),
                               axis.line = element_line(colour = "black"), 
                               axis.text.y = element_blank())

如果没有scale_y_time(),这就是我的图表的样子 https://imgur.com/eEIrF3k

所以我的问题是:

  1. 如何确定y比例,因此我的2个图具有可比性。

  2. 如何将其转换为时间标度(我尝试使用scale_y_time()来实现),这给了我错误的数字,因为674分钟约为11个小时。


样本数据

dput(Maps)
structure(list(Name = c("2y", "2y", "2y", "2y", "2y", "2y", "2y", 
"2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", 
"2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", 
"2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", 
"2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", 
"2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", 
"2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", 
"2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", 
"2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", 
"2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", 
"2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", 
"2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", "2y", 
"2y", "2y", "2y", "2y", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", 
"5F", "5F", "5F", "5F", "5F", "5F", "5F", "5F", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", 
"6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "6h", "9Y", 
"9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", 
"9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", 
"9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", 
"9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", 
"9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y", 
"9Y", "9Y", "9Y", "9Y", "9Y", "9Y", "9Y"), I = c(19.97, 22.01, 
22.96, 14.01, 14.18, 14.2, 14.38, 14.26, 14.84, 14.75, 22.61, 
23.13, 23.57, 23.27, 23.41, 21.69, 22.18, 22.62, 20.67, 17.94, 
18.36, 17.73, 17.03, 16.74, 16.87, 16, 14.64, 14.27, 13.84, 13.72, 
14.77, 14.67, 16.06, 16.76, 16.65, 17.79, 17.89, 18.08, 17.36, 
19.05, 18.5, 19.09, 18.45, 17.77, 16.51, 16.2, 16.32, 16.5, 16.48, 
16.54, 15.85, 15.64, 15.51, 16.12, 15.79, 14.84, 15.32, 14.96, 
15.03, 15, 15.47, 15.26, 14.61, 14.36, 14.92, 14.58, 14.47, 15.81, 
14.3, 14.83, 15.05, 15.78, 15.87, 16.25, 16.64, 16.57, 17.54, 
17.18, 16.67, 18.31, 18.03, 18.22, 19.16, 19.63, 19.34, 20.31, 
20.22, 20.85, 21.16, 19.92, 19.34, 19.57, 18.73, 19.96, 20.24, 
19.62, 20.6, 22.13, 24.23, 20.38, 18.51, 15.47, 15.13, 14.61, 
14.19, 13.96, 13.88, 13.63, 13.62, 13.97, 13.96, 14.32, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 9.855, 10, 10.16, 
10.13, 10.4, 10.46, 1.952, 3.295, 7.433, 8.995, 10.19, 10.55, 
10.46, 10.27, 10.3, 11.34, 10.83, 10.21, 10.37, 9.966, 10.15, 
10.17, 9.916, 10, 10.26, 10.64, 10.51, 8.985, 3.255, 5.213, 4.994, 
3.917, 3.537, 3.811, 3.99, 4.51, 4.241, 3.934, 3.734, 3.492, 
4.565, 4.311, 4.356, 3.91, 3.007, 3.862, 2.745, 2.519, 2.706, 
4.16, 4.23, 2.223, 1.036, 1.423, 1.599, 2.038, 1.673, 1.685, 
1.651, 1.693, 2.411, 2.486, 1.252, 1.267, 1.297, 1.672, 1.514, 
1.443, 1.505, 1.545, 2.211, 1.87, 1.656, 1.778, 1.551, 2.092, 
1.969, 1.836, 1.838, 2.018, 2.97, 1.989, 1.876, 3.294, 3.444, 
2.731, 3.346, 3.808, 2.886, 1.773, 2.015, 2.395, 2.031, 2.501, 
3.331, 3.681, 3.831, 4.076, 3.695, 2.263, 1.903, 1.333, 0.9558, 
0.7116, 0.5624, 0.7542, 0.4521, 0.4954, 0.286, 0.2333, 0.2285, 
0.3505, NA, NA, NA, NA, NA, NA, 0.1952, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1.577, 7.862, 3.904, 
2.758, 2.507, 2.801, 2.564, 2.412, 2.256, 2.368, 2.566, 2.611, 
2.32, 2.007, 2.076, 2.397, 2.244, 2.126, 1.791, 2.028, 2.308, 
2.197, 2.042, 2.07, 1.967, 1.805, 1.816, 1.753, 1.603, 1.542, 
1.842, 1.775, 1.631, 1.167, 1.283, 1.339, 1.097, 1.219, 1.118, 
1.061, 1.2, 1.316, 1.074, 0.9481, 0.8482, 1.23, 1.115, 0.6687, 
1.089, 1.111, 1.537, 1.807, 1.282, 1.161, 1.149, 1.423, 0.9221, 
0.8601, 0.9378, 0.7574, 1.226, 1.154, 0.9973, 1.089, 1.111, 1.136, 
0.9835, 0.9445, 0.8478, 1.08, 1.407, 0.9757, 1.13, 1.073, 1.395, 
1.347, 1.03, 0.8114, 0.9758, 0.7854, 1.31, 1.305, 0.6782, 1.255, 
0.6858, 0.8024, 0.5308, 0.5944, 0.4199, 0.2943, 0.7276, 0.4245, 
0.3462, 0.66, 0.4549, 0.4903, 0.5234, 0.3615, 0.3177, 0.369, 
0.5269, 0.4606, 0.2122, NA, NA, 0.2402, 0.1906, NA, 0.1716, NA, 
0.189, 0.3059, NA, 0.2225, 0.502, 0.433, 0.19, 0.2391, 7.994, 
7.95, 8.115, 8.208, 8.144, 8.223, 8.334, 8.086, 8.172, 8.143, 
8.265, 8.15, 8.485, 8.155, 8.366, 8.294, 8.35, 8.344, 8.426, 
8.35, 8.41, 8.511, 8.358, 8.456, 8.425, 8.446, 8.519, 8.279, 
8.338, 8.457, 8.121, 8.184, 8.371, 8.489, 8.406, 8.323, 8.44, 
8.369, 8.324, 8.384, 8.422, 8.634, 8.689, 8.665, 8.737, 8.706, 
8.646, 8.556, 8.662, 8.567, 8.663, 8.639, 8.605, 8.542, 8.557, 
8.544, 8.506, 8.447, 8.695, 8.667, 8.6, 8.553, 8.52, 8.647, 8.515, 
8.561, 8.708, 8.669, 8.575, 8.483, 8.542, 8.498, 8.434, 8.499, 
8.481, 8.479, 8.555, 8.581, 8.587, 8.421, 8.513, 8.447, 8.463, 
8.393, 8.266, 8.517, 8.509, 8.38, 8.522, 8.183, 6.91, 8.148, 
10.69, 12.31, 13.61, 9.482, 10.54, 10.4, 10.33, 10.12, 10.13, 
12.62, 14.11, 14.1, 14.27, 11.53, 12.8, 10.42, 8.833, 7.451, 
7.777, 4.707, 4.834, 4.978, 5.165, 5.252, 5.596, 5.636, 5.711, 
5.681, 5.603, 5.598, 5.49, 5.496, 5.67, 5.941, 5.973, 6.221, 
6.202, 6.166, 6.269, 6.146, 6.188, 6.203, 6.254, 6.117, 6.196, 
6.149, 6.086, 6.033, 6.084, 6.042, 6.097, 5.99, 5.943, 5.913, 
5.89, 6.058, 6.057, 6.118, 6.141, 6.183, 6.007, 6.07, 5.949, 
6.014, 6.005, 6.07, 6.08, 6.082, 6.127, 6.136, 6.153, 6.124, 
6.405, 6.315, 6.253, 10.06, 10.01, 10.75, 10.31, 9.589, 9.589, 
10.28, 10.19, 10.1, 10.04, 9.947, 10.38, 10.56, 10.25, 9.239, 
9.01, 10.02, 9.866, 9.751, 9.715, 9.729, 9.803, 10.49, 9.686, 
8.48, 8.445, 9.794, 9.468, 9.713, 9.377, 9.544, 10.09, 10.57, 
9.632, 8.876, 8.96, 11.57, 9.767, 9.931, 9.634, 9.816, 10.52, 
10.44, 10.05, 9.858, 10.19, 10.42, 9.819, 8.687, 9.697, 9.332, 
10.36, 9.905, 9.504, 9.573, 9.524, 10.05, 9.579, 9.026, 9.306, 
9.32, 9.924, 9.663), C = c(63.89, 61.28, 60.04, 78.46, 78.44, 
77.59, 77.44, 76.75, 77.33, 77.17, NA, NA, NA, NA, NA, NA, NA, 
66.79, 73.06, 77.75, 76.59, 74.54, 75.15, 73.92, 72.63, 74.62, 
78.06, 78.22, 80.39, 80.91, 78.31, 81.39, 76.98, 77.1, 80.32, 
82.1, 84.81, 81.72, 89.64, 82.55, 82.3, 79.59, 81.75, 82.09, 
83.22, 80.29, 80.11, 78.4, 79.01, 78.57, 79.42, 80.48, 79.5, 
76.8, 80.11, 83.95, 81.38, 80.51, 83.06, 82.76, 79.93, 83.28, 
82.89, 84.45, 90.18, 92.82, 84.44, 82.01, 85.37, 82.36, 86.15, 
81.86, 82.99, 84.95, 91.86, 102.43, 83.76, 84.62, 85.73, 81.79, 
81.97, 80.33, 77.06, 77.04, 75.55, 72.59, 76.58, 70.77, 71.68, 
73.62, 77.47, 75.8, 78.6, 72.93, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, 74.415, 70.44, 72.53, 73.03, 
72.97, 73.93, NA, NA, NA, NA, NA, 72.29, 70.27, 68.92, 69.11, 
69.6, 67.38, 69.56, 68.94, 67.904, 64.09, 64.05, 62.874, 63.22, 
64.06, 63.09, 61.48, 62.405, 81.705, 84.637, 86.796, 85.233, 
82.113, 77.919, 75, 75.38, 73.969, 72.276, 72.126, 76.638, 76.055, 
76.939, 87.824, 98.99, 93.853, 105.838, 99.255, 93.841, 89.034, 
98.44, 108.17, 95.997, 82.344, 79.157, 75.121, 69.522, 65.967, 
64.015, 65.149, 67.777, 69.029, 85.624, 86.318, 80.173, 80.233, 
79.018, 78.836, 78.657, 78.135, 77.715, 77.199, 76.75, 76.684, 
76.402, 77.389, 76.628, 78.511, 81.074, 86.942, 87.172, 84.74, 
89.361, 89.004, 88.876, 86.016, 87.879, 86.594, 85.752, 85.674, 
96.217, 96.675, 91.495, 88.869, 82.519, 82.869, 78.009, 74.519, 
73.344, 80.095, 81.327, 80.007, 79.057, 77.0842, 76.3884, 76.5876, 
75.4558, 76.4579, 75.6846, 76.074, 75.2567, 72.7915, 77.8595, 
NA, NA, NA, NA, NA, NA, 76.8548, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 94.803, 87.838, 91.936, 
96.672, 96.993, 93.479, 90.566, 89.898, 92.974, 89.882, 87.974, 
86.819, 90.47, 89.373, 86.194, 84.713, 89.066, 87.904, 85.499, 
83.982, 87.802, 88.153, 86.358, 86.11, 91.573, 92.045, 90.214, 
90.437, 91.297, 88.828, 89.178, 91.985, 89.609, 90.053, 90.177, 
94.581, 90.473, 88.491, 91.772, 89.289, 88.05, 88.214, 90.516, 
88.2819, 87.6818, 91.55, 87.995, 88.6413, 90.061, 93.999, 88.563, 
87.423, 90.238, 89.659, 88.541, 93.677, 92.2679, 90.0399, 94.2822, 
93.2626, 90.364, 92.386, 93.5427, 89.961, 92.539, 94.954, 91.7765, 
94.9555, 93.9822, 92.6, 95.133, 93.3843, 88.96, 91.967, 96.075, 
91.673, 93.38, 91.7386, 88.7242, 91.9546, 90.87, 89.785, 98.7218, 
98.515, 89.4242, 93.3076, 90.3292, 87.9856, 92.1001, 87.7357, 
87.6324, 90.5955, 89.3638, 88.92, 92.1551, 90.8397, 89.2566, 
91.5785, 88.5623, 88.101, 91.2331, 90.2994, 89.6478, NA, NA, 
87.9898, 90.3094, NA, 85.9184, NA, 87.771, 88.6441, NA, 88.7475, 
88.048, 91.867, 87.61, 87.9109, 73.636, 74.21, 73.015, 73.032, 
72.286, 73.027, 72.646, 72.904, 74.138, 74.647, 74.955, 75.28, 
74.535, 75.635, 75.364, 75.626, 76.01, 76.946, 76.144, 77.8, 
77.83, 78.539, 77.682, 78.514, 77.875, 78.824, 78.641, 79.461, 
79.672, 79.053, 80.869, 81.106, 80.169, 78.021, 81.284, NA, 79.98, 
80.281, 80.146, 81.156, 81.478, 82.196, 81.971, 83.315, 83.633, 
82.854, 83.004, 83.554, 82.758, 82.283, 82.607, 82.331, 83.015, 
83.408, 82.783, 84.326, 84.414, 84.233, 84.405, 84.273, 84.77, 
84.907, 85.17, 86.083, 85.525, 86.469, 86.742, 86.481, 85.785, 
85.737, 85.068, 85.442, 84.666, 84.321, 84.309, 84.121, 84.635, 
83.819, 84.373, 84.159, 83.507, 84.223, 83.677, 84.177, 83.254, 
81.713, 82.581, 81.82, 82.438, 83.317, 84.37, 85.932, 97.01, 
97.59, 97.09, 94.618, 96.36, 93.3, 92.87, 94.38, 97.37, 97.78, 
95.29, 96.7, 96.43, 97.97, 97.8, 99.28, 99.267, 100.849, 94.523, 
87.923, 86.196, 85.482, 85.395, 85.338, 83.804, 86.224, 86.849, 
87.589, 88.357, 87.682, 89.83, 88.554, 89.49, 87.819, 88.377, 
88.519, 88.498, 88.524, 88.901, 90.254, 88.472, 89.137, 88.736, 
90.653, 90.194, 90.121, 90.414, 90.367, 89.996, 90.598, 90.453, 
90.33, 90.737, 90.677, 90.95, 91.442, 90.403, 90.512, 90.659, 
91.697, 92.233, 90.43, 90.521, 90.126, 90.325, 90, 89.95, 89.908, 
89.463, 89.284, 88.927, 88.966, 87.365, 86.945, 83.807, 72.3, 
72.55, 73.57, 72.4, 74.551, 74.971, 73.73, 75.43, 74.49, 72.81, 
72.053, 72.71, 73.76, 73.11, 74.381, 73.87, 72.91, 73.834, 74.889, 
73.695, 73.021, 71.297, 73.41, 72.754, 73.41, 72.675, 72.226, 
73.842, 74.827, 74.563, 75.236, 75.91, 76.69, 77.148, 78.494, 
78.45, 77.43, 80.483, 79.759, 79.326, 78.864, 79.34, 80.27, 81.92, 
82.072, 81.84, 82.43, 83.311, 83.363, 82.593, 82.368, 82.82, 
83.595, 83.766, 84.017, 83.216, 83.41, 84.711, 83.824, 83.304, 
82.93, 83.546, 84.307)), row.names = c(NA, -674L), class = c("tbl_df", 
"tbl", "data.frame"))

1 个答案:

答案 0 :(得分:0)

由于缺少颜色变量,您的数据仍然不是用于生成绘图的全套数据。我认为您不应该使用scale_*_time,因为它们通常用于处理日期时间对象。假设您的时间单位是秒,则可以执行以下操作:

library("ggplot2")
library("reshape2")

df <- read.delim("~/tmp.csv")
mdf <- melt(df, id.var="Name")

ggplot(mdf, aes(x = Name, y = value / 3600)) +
    facet_wrap(~variable, ncol = 1) +
    geom_bar(stat="identity") +
    labs(x = "Patient", y = "Time (hr)") +
    coord_flip()
#> Warning: Removed 243 rows containing missing values (position_stack).

reprex package(v0.3.0)于2019-11-07创建