【发布时间】:2017-05-21 18:10:29
【问题描述】:
我正在考虑如何在晶须图中呈现部分值/...
M2 只有最大值。
两种测量都没有
图1中输出的代码
library("reshape2")
library("ggplot2")
ds <- structure(list(Vars = c("M1", "M2", "M1", "M2", "M1", "M2"),
variable = structure(c(1L, 1L, 2L, 2L, 3L, 3L), .Label = c("Max",
"Ave", "Min"), class = "factor"), value = c("150",
"61", " 60", NA, " 41", NA)), row.names = c(NA, -6L), .Names = c("Vars",
"variable", "value"), class = "data.frame")
# http://stackoverflow.com/q/44100187/54964 eipi10
ds$value = as.numeric(ds$value)
# http://stackoverflow.com/a/44090815/54964
minmax <- ds[ds$variable %in% c("Min","Max"), ]
absol <- ds[ds$variable %in% c("Ave"), ]
# absol <- ds[ds$variable %in% c("Ave", "Absolute"), ]
minm <- dcast(minmax, Vars ~ variable)
absol <- merge(absol, minm, by = "Vars", all.x = T)
absol
ggplot(absol, aes(x = Vars, y = value, fill = variable)) +
geom_bar(stat = "identity") +
geom_errorbar(aes(ymin = Min, ymax = Max), width = .25)
开始时的值
Max Ave Min Vars
M1 150 60 41 M1
M2 61 <NA> <NA> M2
图。 1 只有最大值存在时没有可视化的输出
M1 在条形图中的表示也很奇怪,因为数据中没有绝对值,最初是在 absol 中设计的。
预期输出:在M2 演示文稿中标记最大值
操作系统:Debian 8.7
R:3.4(向后移植)
【问题讨论】:
-
value是您数据中的一个字符变量,因此它被视为情节中的一个因素。创建ds时,不要在value中的数字周围加上引号,这样value将是数字。或者你可以做ds$value = as.numeric(ds$value)。 -
@eipi10 我在正文中添加了修复程序。 y 轴现在看起来没问题,但除此之外,同样的情况仍然存在。你怎么看?