我正在尝试在R中制作堆叠条形图,但出于某种原因,当我运行时,我在运行代码时会得到一个非常奇怪的结果。
library(ggplot2)
library(ggplotly)
p <- ggplot(occupation.a, aes(x= "Standardised death rate per 1000", y= "x", fill= "Occupation"))
p<- p + geom_bar(stat = "identity", position = "stack")
ggplotly(p)
我想知道我的代码出了什么问题,我提供了我正在使用的数据,如果这在以下链接中有帮助的话。 https://drive.google.com/file/d/0B8OiynRpywV8bzhWM2Y2Tzd4bFU/view?usp=sharing
感谢您提前提供任何帮助。
structure(list(`Standardised death rate per 1000` = c(3.4, 3.8,
4, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5, 5.1, 5.2,
5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6, 6.1, 6.2, 6.3, 6.4, 6.5,
6.6, 6.7, 6.8, 6.9, 7, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8,
7.9, 8, 8.1, 8.2, 8.3, 8.4, 8.6, 8.7, 8.8, 9.3, 9.7, 11, 15.6,
3.4, 3.8, 4, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5,
5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6, 6.1, 6.2, 6.3,
6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6,
7.7, 7.8, 7.9, 8, 8.1, 8.2, 8.3, 8.4, 8.6, 8.7, 8.8, 9.3, 9.7,
11, 15.6, 3.4, 3.8, 4, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8,
4.9, 5, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6, 6.1,
6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7, 7.1, 7.2, 7.3, 7.4,
7.5, 7.6, 7.7, 7.8, 7.9, 8, 8.1, 8.2, 8.3, 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L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L), .Label = c("Labourers", "Administrative workers", "Community personal service workers",
"Inadequatly dscribed", "Machine operators/ Drivers", "Managers",
"Professionals", "Sales workers", "technicians and trade workers"
), class = "factor"), x = c(10.3, 1.8, 3, 1.7, 13.4, 28.6, 12.2,
26.7, 24.8, 7.6, 45, 72.5, 54.8, 130, 89.2, 57.1, 39.8, 97.9,
153.5, 108.5, 161.2, 204.8, 142.1, 297.6, 242, 209.3, 204.9,
295.7, 171, 188.1, 134.1, 114.5, 167.5, 178.3, 99.3, 76.8, 75.7,
71.4, 62.3, 30.3, 14.5, 61.1, 50, 22.6, 29.5, 23.5, 29.7, 54.6,
12, 25.7, 30.4, 9.2, 20.6, 9.4, 10.7, 14.1, 12.9, 12.2, 41, 34.5,
30.3, 58.7, 59.3, 41.5, 100.1, 139.3, 92.7, 153.8, 106.4, 87.8,
57.5, 108.4, 242.6, 136.4, 189.1, 259.7, 200.4, 303.5, 256.7,
204.2, 214.9, 281.1, 140.3, 157, 125.8, 105.7, 138.7, 164.4,
95.6, 72.9, 57.7, 55.4, 40.4, 20.8, 9.4, 42.3, 47.3, 31.3, 18,
15.9, 19.8, 49.7, 10.4, 21.9, 19.5, 11.2, 10.2, 14.3, 9.7, 5.9,
7.8, 6.5, 25.5, 25.6, 18.6, 33.2, 35.6, 21.3, 58.8, 89, 67.6,
109.7, 73.3, 59, 36.9, 87.7, 153, 94, 135.9, 200.3, 133.1, 238.2,
206.8, 155.3, 173.9, 214.2, 113, 135.3, 112.7, 84.6, 115.2, 143.3,
81.1, 62.2, 49.3, 45.9, 36.4, 15.6, 8.6, 39.9, 42.3, 25.1, 25.6,
21.2, 21.4, 49.7, 11.7, 26.4, 21.9, 8.1, 14.5, 15.4, 1.5, 1.8,
1.8, 2.5, 4.6, 4.6, 2.7, 6.4, 7.6, 6.1, 12.9, 17.1, 11.7, 18.9,
13.8, 11.4, 7.9, 17.5, 31.6, 19.1, 25.1, 32.5, 24.1, 46, 36.7,
29.1, 27, 39.2, 20.8, 23.7, 17.9, 17.3, 23.2, 26.9, 13.8, 10.2,
8.7, 9.5, 6.4, 3.4, 2.2, 7.5, 8.4, 3.9, 4.8, 2.9, 3.5, 7.5, 2.2,
3.4, 3.8, 2.5, 3.9, 2.6, 5, 0.8, 1.5, 0.7, 5.8, 19, 5.6, 20.5,
14.4, 3.5, 28, 40.8, 41.6, 63.8, 48, 35, 28.9, 59.4, 104.1, 68.5,
128.2, 127.5, 100, 202.5, 145.7, 140.4, 141.2, 194, 112.4, 103.4,
74.6, 79.4, 120, 124.2, 74.6, 50.3, 38.7, 39.6, 38.9, 15.7, 14.6,
40.7, 51.8, 19.3, 12.7, 14.3, 26.1, 30.8, 6.7, 12.8, 16, 17.1,
6.5, 5.6, 20.7, 20.2, 20.5, 22.1, 51.4, 66.7, 27.8, 58.2, 69.3,
59.1, 104.8, 158.2, 95.6, 212.7, 124.4, 69.6, 62.3, 170.5, 207.5,
158.4, 189.7, 316, 196.2, 377.3, 284.8, 315.6, 263.6, 323, 211,
220.6, 187.8, 133.8, 192.1, 227.3, 114.8, 114.7, 93.8, 116.2,
86.2, 44.9, 14.6, 65, 46.1, 22.1, 50.1, 62, 36.2, 56.4, 18.2,
32.9, 48.7, 8.1, 9.8, 11.4, 19.3, 43.6, 37.4, 42.4, 111.8, 65,
62.9, 104.8, 105.9, 119.9, 217.1, 276.8, 173.5, 239.7, 171.4,
136.9, 69, 167.6, 320.3, 181.4, 222.4, 396.8, 269.6, 448.4, 325.2,
261.6, 256, 339.5, 154.6, 172.7, 199.4, 131.3, 152, 207.7, 129.8,
80.9, 70.1, 62.4, 44.5, 26.9, 12.2, 47.7, 50.6, 20.9, 23.4, 25.3,
20.5, 61.1, 14.8, 31.5, 22.1, 15.1, 19.4, 17.1, 7.6, 6.4, 7.9,
7.5, 22.2, 20.9, 18, 36.6, 38, 23.5, 60.3, 92.7, 58.9, 106.4,
66.2, 57.4, 35, 71.9, 150.3, 86.7, 124.7, 182, 124.7, 221.8,
198.2, 143.7, 152, 190.5, 100.8, 115.1, 100.4, 81.4, 100.7, 114.6,
71.5, 48.5, 40.6, 37.6, 30.9, 14.8, 7.9, 35.3, 33.5, 18, 13.5,
12.9, 10.8, 31.1, 6.8, 17.1, 13.1, 6.4, 3.9, 6.4, 15.2, 5.3,
7.3, 4.4, 24.3, 35, 22.1, 54.9, 45.7, 17.6, 73.4, 114.3, 104.1,
165.3, 107.6, 86, 62.8, 119.5, 237.6, 147.2, 224.5, 281.1, 210.7,
365.8, 304.9, 242, 267.6, 322.9, 176.5, 185, 148.1, 152.6, 190.9,
214.6, 120.2, 83.8, 65.9, 62.2, 54.4, 27.7, 16.1, 60.6, 70.5,
36.9, 22.5, 22.1, 32.2, 59.3, 17.2, 28.4, 24.7, 22.4, 11.3, 17.9
)), .Names = c("Standardised death rate per 1000", "Occupation",
"x"), row.names = c(NA, -486L), class = "data.frame")