我试图在R中绘制一个图,其中X轴是数字,Y轴是标签。例如,数据如下所示:
> dput(head(d.current))
structure(list(H1 = c("NA11830", "NA12004", "NA06985"), H2 = c("NA11993",
"NA11993", "NA11993"), H3 = c("NA12763", "NA12763", "NA12763"
), nABBA = c(225L, 217L, 242L), nBABA = c(336L, 267L, 302L),
Dstat = c(-0.197861, -0.1033058, -0.1102941), jackEst = c(-0.197861,
-0.1033058, -0.1102941), SE = c(0.08514797, 0.09471542, 0.1241554
), Z = c(-2.323731, -1.090697, -0.8883553), X = c(NA, NA,
NA)), .Names = c("H1", "H2", "H3", "nABBA", "nBABA", "Dstat",
"jackEst", "SE", "Z", "X"), row.names = 4:6, class = "data.frame")
我试图制作一个类似于此部分的数字: http://www.nature.com/articles/nplants20143/figures/1
这就是我现在所拥有的:
plot(x=d.current$Dstat, d.current$H1, pch=19)
segments(d.current$Dstat-d.current$SE, as.numeric(d.current$H1),d.current$Dstat+d.current$SE, as.numeric(d.current$H1))
这是我得到的错误:
Error in plot.window(...) : need finite 'ylim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf
答案 0 :(得分:1)
你的y变量是一个字符向量。 R不知道NA11830是在NA12004之前还是之后。如果你把它转换成一个因子,你会得到一个情节。
编辑:
您可以使用网格包中的dotplot
函数来扩展基本R图形。
library(lattice)
dotplot(factor(d.current$H1) ~ d.current$Dstat)