我想繪製一個堆積的條形圖,但我錯過了一些東西。我有以下數據表樣本:用數據表繪製一個堆積的條形圖
hdisk86 hdisk88 hdisk90 hdisk89 hdisk91 hdisk92 hdisk93 hdisk94 hdisk96
1: 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0 0
hdisk95 hdisk98 hdisk97 hdisk99 hdisk100 hdisk101 hdisk102 hdisk103 hdisk108
1: 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0 0
hdisk107 hdisk104 hdisk105 hdisk109 hdisk110 hdisk112 hdisk111 hdisk113
1: 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0
hdisk114 hdisk115 hdisk116 hdisk117 hdisk87 hdisk118 hdisk120 hdisk119
1: 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0
hdisk122 hdisk123 hdisk124 hdisk125 hdisk121 hdisk127 hdisk126 hdisk2 hdisk3
1: 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0 0
hdisk5 hdisk4 hdisk6 hdisk10 hdisk11 hdisk8 hdisk12 hdisk9 hdisk18 hdisk14
1: 0 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0 0 0
hdisk15 hdisk17 hdisk16 hdisk13 hdisk106 hdisk19 hdisk20 hdisk7 hdisk21
1: 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0 0
hdisk28 hdisk33 hdisk32 hdisk27 hdisk30 hdisk23 hdisk35 hdisk40 hdisk25
1: 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0 0
hdisk41 hdisk39 hdisk38 hdisk43 hdisk22 hdisk36 hdisk31 hdisk45 hdisk29
1: 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0 0
hdisk44 hdisk34 hdisk37 hdisk48 hdisk24 hdisk47 hdisk42 hdisk46 hdisk49
1: 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0 0
hdisk53 hdisk50 hdisk56 hdisk55 hdisk54 hdisk52 hdisk59 hdisk62 hdisk58
1: 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0 0
hdisk64 hdisk61 hdisk65 hdisk60 hdisk67 hdisk66 hdisk57 hdisk51 hdisk69
1: 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0 0
hdisk63 hdisk74 hdisk70 hdisk72 hdisk75 hdisk68 hdisk73 hdisk76 hdisk71
1: 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0 0
hdisk78 hdisk85 hdisk81 hdisk80 hdisk83 hdisk79 hdisk82 hdisk77 hdisk84
1: 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0 0
hdisk26 hdisk0 hdisk1 hdisk128 hdisk129 hdisk130 hdisk131 hdisk132 hdisk133
1: 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0 0
hdisk134 hdisk135 hdisk136 hdisk137 hdisk138 hdisk139 hdisk140 hdisk141
1: 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0
hdisk142 hdisk143 hdisk144 hdisk145 hdisk146 hdisk147 hdisk148 hdisk149
1: 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0
3: 0 0 0 0 0 0 0 0
Summary
1: Avg
2: WAvg
3: Max
我已經使用了熔體功能將數據錶轉換從廣角到長:
d <- grep("hdisk", names(DT), value = T)
DT_mdf <- melt(DT,
id.vars="Summary",
measure.vars=d,
variable.name="hdisks",
value.name="percentage")
,並得到這樣的:
Summary hdisks percentage
1: Avg hdisk86 0
2: WAvg hdisk86 0
3: Max hdisk86 0
4: Avg hdisk88 0
5: WAvg hdisk88 0
---
446: WAvg hdisk148 0
447: Max hdisk148 0
448: Avg hdisk149 0
449: WAvg hdisk149 0
450: Max hdisk149 0
然後我嘗試繪製堆積的條形圖並保存爲PNG文件:
# Plot line graphics...
g1 <- ggplot(DT_mdf, aes(x=hdisks, y=percentage, fill=Summary)) +
geom_bar(stat = "identity") +
theme_excel() +
scale_color_excel() +
scale_fill_excel()
# Saving in png format
png("CPU_ALL_g1.png", width=16*ppi, height=9*ppi, res=ppi)
plot(g1)
dev.off()
我收到以下錯誤信息:
Saving 7 x 7 in image
Don't know how to automatically pick scale for object of type list. Defaulting to continuous
Error in pmin(y, 0) : object 'y' not found
Calls: ggsave ... transform -> transform.data.frame -> eval -> eval -> pmin
Execution halted
難道我有太多的元素一個圖表中繪製?或者是其他東西?
這裏數據表的長格式的示例:
structure(list(Summary = list("Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max", "Avg", "WAvg", "Max"), hdisks = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 9L, 9L, 9L, 10L, 10L, 10L, 11L, 11L, 11L, 12L, 12L, 12L, 13L, 13L, 13L, 14L, 14L, 14L, 15L, 15L, 15L, 16L, 16L, 16L, 17L, 17L, 17L, 18L, 18L, 18L, 19L, 19L, 19L, 20L, 20L, 20L, 21L, 21L, 21L, 22L, 22L, 22L, 23L, 23L, 23L, 24L, 24L, 24L, 25L, 25L, 25L, 26L, 26L, 26L, 27L, 27L, 27L, 28L, 28L, 28L, 29L, 29L, 29L, 30L, 30L, 30L, 31L, 31L, 31L, 32L, 32L, 32L, 33L, 33L, 33L, 34L, 34L, 34L, 35L, 35L, 35L, 36L, 36L, 36L, 37L, 37L, 37L, 38L, 38L, 38L, 39L, 39L, 39L, 40L, 40L, 40L, 41L, 41L, 41L, 42L, 42L, 42L, 43L, 43L, 43L, 44L, 44L, 44L, 45L, 45L, 45L, 46L, 46L, 46L, 47L, 47L, 47L, 48L, 48L, 48L, 49L, 49L, 49L, 50L, 50L, 50L, 51L, 51L, 51L, 52L, 52L, 52L, 53L, 53L, 53L, 54L, 54L, 54L, 55L, 55L, 55L, 56L, 56L, 56L, 57L, 57L, 57L, 58L, 58L, 58L, 59L, 59L, 59L, 60L, 60L, 60L, 61L, 61L, 61L, 62L, 62L, 62L, 63L, 63L, 63L, 64L, 64L, 64L, 65L, 65L, 65L, 66L, 66L, 66L, 67L, 67L, 67L, 68L, 68L, 68L, 69L, 69L, 69L, 70L, 70L, 70L, 71L, 71L, 71L, 72L, 72L, 72L, 73L, 73L, 73L, 74L, 74L, 74L, 75L, 75L, 75L, 76L, 76L, 76L, 77L, 77L, 77L, 78L, 78L, 78L, 79L, 79L, 79L, 80L, 80L, 80L, 81L, 81L, 81L, 82L, 82L, 82L, 83L, 83L, 83L, 84L, 84L, 84L, 85L, 85L, 85L, 86L, 86L, 86L, 87L, 87L, 87L, 88L, 88L, 88L, 89L, 89L, 89L, 90L, 90L, 90L, 91L, 91L, 91L, 92L, 92L, 92L, 93L, 93L, 93L, 94L, 94L, 94L, 95L, 95L, 95L, 96L, 96L, 96L, 97L, 97L, 97L, 98L, 98L, 98L, 99L, 99L, 99L, 100L, 100L, 100L, 101L, 101L, 101L, 102L, 102L, 102L, 103L, 103L, 103L, 104L, 104L, 104L, 105L, 105L, 105L, 106L, 106L, 106L, 107L, 107L, 107L, 108L, 108L, 108L, 109L, 109L, 109L, 110L, 110L, 110L, 111L, 111L, 111L, 112L, 112L, 112L, 113L, 113L, 113L, 114L, 114L, 114L, 115L, 115L, 115L, 116L, 116L, 116L, 117L, 117L, 117L, 118L, 118L, 118L, 119L, 119L, 119L, 120L, 120L, 120L, 121L, 121L, 121L, 122L, 122L, 122L, 123L, 123L, 123L, 124L, 124L, 124L, 125L, 125L, 125L, 126L, 126L, 126L, 127L, 127L, 127L, 128L, 128L, 128L, 129L, 129L, 129L, 130L, 130L, 130L, 131L, 131L, 131L, 132L, 132L, 132L, 133L, 133L, 133L, 134L, 134L, 134L, 135L, 135L, 135L, 136L, 136L, 136L, 137L, 137L, 137L, 138L, 138L, 138L, 139L, 139L, 139L, 140L, 140L, 140L, 141L, 141L, 141L, 142L, 142L, 142L, 143L, 143L, 143L, 144L, 144L, 144L, 145L, 145L, 145L, 146L, 146L, 146L, 147L, 147L, 147L, 148L, 148L, 148L, 149L, 149L, 149L, 150L, 150L, 150L), class = "factor", .Label = c("hdisk86", "hdisk88", "hdisk90", "hdisk89", "hdisk91", "hdisk92", "hdisk93", "hdisk94", "hdisk96", "hdisk95", "hdisk98", "hdisk97", "hdisk99", "hdisk100", "hdisk101", "hdisk102", "hdisk103", "hdisk108", "hdisk107", "hdisk104", "hdisk105", "hdisk109", "hdisk110", "hdisk112", "hdisk111", "hdisk113", "hdisk114", "hdisk115", "hdisk116", "hdisk117", "hdisk87", "hdisk118", "hdisk120", "hdisk119", "hdisk122", "hdisk123", "hdisk124", "hdisk125", "hdisk121", "hdisk127", "hdisk126", "hdisk2", "hdisk3", "hdisk5", "hdisk4", "hdisk6", "hdisk10", "hdisk11", "hdisk8", "hdisk12", "hdisk9", "hdisk18", "hdisk14", "hdisk15", "hdisk17", "hdisk16", "hdisk13", "hdisk106", "hdisk19", "hdisk20", "hdisk7", "hdisk21", "hdisk28", "hdisk33", "hdisk32", "hdisk27", "hdisk30", "hdisk23", "hdisk35", "hdisk40", "hdisk25", "hdisk41", "hdisk39", "hdisk38", "hdisk43", "hdisk22", "hdisk36", "hdisk31", "hdisk45", "hdisk29", "hdisk44", "hdisk34", "hdisk37", "hdisk48", "hdisk24", "hdisk47", "hdisk42", "hdisk46", "hdisk49", "hdisk53", "hdisk50", "hdisk56", "hdisk55", "hdisk54", "hdisk52", "hdisk59", "hdisk62", "hdisk58", "hdisk64", "hdisk61", "hdisk65", "hdisk60", "hdisk67", "hdisk66", "hdisk57", "hdisk51", "hdisk69", "hdisk63", "hdisk74", "hdisk70", "hdisk72", "hdisk75", "hdisk68", "hdisk73", "hdisk76", "hdisk71", "hdisk78", "hdisk85", "hdisk81", "hdisk80", "hdisk83", "hdisk79", "hdisk82", "hdisk77", "hdisk84", "hdisk26", "hdisk0", "hdisk1", "hdisk128", "hdisk129", "hdisk130", "hdisk131", "hdisk132", "hdisk133", "hdisk134", "hdisk135", "hdisk136", "hdisk137", "hdisk138", "hdisk139", "hdisk140", "hdisk141", "hdisk142", "hdisk143", "hdisk144", "hdisk145", "hdisk146", "hdisk147", "hdisk148", "hdisk149")), percentage = list(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), .Names = c("Summary", "hdisks", "percentage" ), row.names = c(NA, -450L), class = c("data.table", "data.frame" ), .internal.selfref = <pointer: 0x1d47ec8>)
是否所有值的百分比列0?如果是的話,那麼它不會繪製圖表 –
爲什麼?在我的理解中,我應該繪製一張無條形的條形圖,或者全部位於X軸的最高點。 –
只有0的數據確實應該產生一個空的圖。你能在R裏面生成圖嗎? (只是通過運行'g1?')我無法用一些模擬的零複製你的錯誤。你能使用'dput(DT_mdf)'提供(部分)你的實際數據嗎? – Heroka