【问题标题】:R categorical y axisR分类y轴
【发布时间】:2015-04-14 04:34:51
【问题描述】:

我正在尝试在 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

【问题讨论】:

  • 您共享的数据包含XY 列。您共享的代码包含 DstatH1SE 列。您如何与dput(head(d.current)) 分享前几行真实数据。或者,如果您不介意 ggplot,请查看 geom_errorbarh
  • 当然。只是认为使用假示例数据可能更简单,因为我只绘制两列,其余的无关紧要。我想为此使用base R。
  • 因为您使用的是细分,所以 SE 似乎很重要。

标签: r plot


【解决方案1】:

您的 y 变量是一个字符向量。 R 不知道 NA11830 是在 NA12004 之前还是之后。如果你把它转换成一个因子,你会得到一个情节。

编辑:

您可以使用 lattice 包中的dotplot 函数来扩展基础 R 图形。

library(lattice)
dotplot(factor(d.current$H1) ~ d.current$Dstat)

【讨论】:

  • 对,但这给了我一个 Y 轴是数字的图。我想将标签保留在 Y 轴上。
猜你喜欢
  • 2020-11-19
  • 1970-01-01
  • 2014-02-21
  • 1970-01-01
  • 2012-06-08
  • 2019-10-21
  • 2018-01-30
  • 1970-01-01
  • 2014-12-03
相关资源
最近更新 更多