> dput(data)
structure(list(Vascular_Pathology_M = structure(c(1L, 2L, 3L,
1L, 1L, 2L, 4L, 3L, 1L, 2L, 3L, 2L, 1L, 3L, 2L, 3L, 3L, 3L, 4L,
2L, 2L, 2L, 2L, 2L, 3L, 2L, 1L, 3L, 3L, 3L), .Label = c("Absent",
"Mild", "Mild/Moderate", "Moderate/Severe", "Severe"), class = "factor"),
Output = c(1.01789418758932, 1.05627630598801, 1.49233946102323,
1.38192374975672, 1.13097652937671, 0.861306979571144, 0.707820561413699,
1.16628243128399, 0.983163398006992, 1.23972603843843, 0.822709564829401,
0.90516107062003, 0.79080293468606, 0.886130998081624, 1.2674953773847,
0.984695292355941, 1.1781360057546, 0.858847379047159, 0.772681010534905,
1.04401349705871, 0.998339856427367, 1.12106301647898, 0.835132782324955,
0.710123766831317, 1.01005735218463, 1.05588470743658, 0.913371462992548,
1.10995126470399, 1.18574975368509, 1.17712141366123)), .Names = c("Vascular_Pathology_M",
"Output"), row.names = c(1L, 3L, 4L, 5L, 6L, 7L, 8L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L), class = "data.frame")
> data
Vascular_Pathology_M Output
1 Absent 1.0178942
3 Mild 1.0562763
4 Mild/Moderate 1.4923395
5 Absent 1.3819237
6 Absent 1.1309765
7 Mild 0.8613070
8 Moderate/Severe 0.7078206
10 Mild/Moderate 1.1662824
11 Absent 0.9831634
12 Mild 1.2397260
13 Mild/Moderate 0.8227096
14 Mild 0.9051611
15 Absent 0.7908029
16 Mild/Moderate 0.8861310
17 Mild 1.2674954
18 Mild/Moderate 0.9846953
19 Mild/Moderate 1.1781360
20 Mild/Moderate 0.8588474
21 Moderate/Severe 0.7726810
22 Mild 1.0440135
23 Mild 0.9983399
24 Mild 1.1210630
25 Mild 0.8351328
26 Mild 0.7101238
27 Mild/Moderate 1.0100574
28 Mild 1.0558847
29 Absent 0.9133715
30 Mild/Moderate 1.1099513
31 Mild/Moderate 1.1857498
32 Mild/Moderate 1.1771214
使用上述数据集,我想绘制密度图(x轴上的输出,按血管病变的严重程度分组和着色)。
这是这个blog post的示例情节,而不是方法1 2 3,在我的情况下,我会有缺席,温和,温和/中等,中等/严重,严重。在该博客文章中,作者使用函数stack
来重新组织数据。但是,由于我的数据格式不同,我似乎无法使用相同的方法。
答案 0 :(得分:2)
这应该适合你。
require(ggplot2)
ggplot(data, aes(x = Output, fill = Vascular_Pathology_M)) +
geom_density(alpha = 0.3)