【发布时间】:2015-09-30 13:50:40
【问题描述】:
我的数据框:
N P E S
W1 3.5 3.5 3.4 3.5
w2 3.4 3.7 3.6 3.5
w3 3.5 3.4 3.5 3.5
w4 3.5 3.4 3.5 3.5
w5 3.5 3.4 3.5 3.5
w6 3.5 3.4 3.5 3.5
w7 3.5 3.4 3.5 3.5
w8 3.5 3.4 3.5 3.5
条形图的代码
mat <- as.matrix(t(tabela.matrix))
qw <- barplot(mat, beside = TRUE, axisnames = FALSE, ylim = c(0, 6),
col = c("yellow", "deepskyblue1", "yellowgreen", "orchid4"))
text(colMeans(qw[2:3, ]), -0.25, labels = colnames(mat), xpd = TRUE, srt = 15)
text(qw, 0, round(as.matrix(t(tabela.matrix)), 1), cex = 1, pos = 3, srt = 90)
legend(3.2, -0.6, c("N","P","E", "S"),
fill = c("yellow", "deepskyblue1", "yellowgreen", "orchid4"),
horiz = TRUE, xpd = TRUE)
所以在我的条形图上,我需要添加line,表示减法:每行的最大值-最小值。所以我使用下面的代码来获得减法。
max.tmp <- apply(df, 1, max)
min.tmp <- apply(df, 1, min)
substr.tmp <- max.tmp - min.tmp
现在我想在substr.tmp 中添加指示值的红线。代码lines() 不起作用。
我的输出(红线)应该“看起来”像这样(它是图片形式的 excel,我有兴趣添加行,而不是图片本身的数据)
一个dput的数据:
structure(c(3.46666666666667, 3.35, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.45555555555556, 3.7, 3.36666666666667, 3.36666666666667, 3.36666666666667, 3.36666666666667, 3.36666666666667, 3.36666666666667, 3.40769230769231, 3.57692307692308, 3.53846153846154, 3.53846153846154, 3.53846153846154, 3.53846153846154, 3.53846153846154, 3.53846153846154, 3.51122994652406, 3.5156862745098, 3.49090909090909, 3.49090909090909, 3.49090909090909, 3.49090909090909, 3.49090909090909, 3.49090909090909 ), .Dim = c(8L, 4L), .Dimnames = list(c("a", "b", "c", "d", "e", "f", "g", "h"), NULL))
【问题讨论】:
-
可以添加数据框的
dput -
@ RBM,在这里它是结构(C(3.46666666666667,3.35,3.5,3.5,3.5,3.5,3.5,3.5,3.45555555555556,3.7,3.36666666666667,3.36666666666667,3.36666666666667,3.36666666666667,3.36666666666667 ,3.36666666666667,3.40769230769231,3.57692307692308,3.53846153846154,3.53846153846154,3.53846153846154,3.53846153846154,3.53846153846154,3.53846153846154,3.51122994652406,3.5156862745098,3.49090909090909,3.49090909090909,3.49090909090909,3.49090909090909,3.49090909090909,3.49090909090909),.dim伪= C(8L,4L),.Dimnames =列表(c("a", "b", "c", "d", "e", "f", "g", "h"), NULL))'
-
您的图表不同 - 第一个在 y 轴上为 0 到 3.5,第二个接近 6。同样在
max.tmp <- apply(df, 1, max)中,不清楚df是什么。你能发布带有dputinit 的整个可运行示例。 -
第二张图片来自excel,是别人生成的。我生成了第一张图片,我只需要绘制 line 就像它在第二张图片中一样。