ohblahitsme
ohblahitsme

Reputation: 1071

R categorical y axis

I'm trying to make a plot in R where the X axis is numeric and the Y axis is a label. For example, the data looks like:

> 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")

I'm trying to make a figure like the one in part a of this: enter image description herehttp://www.nature.com/articles/nplants20143/figures/1

Here's what I have right now:

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))

and this is the error I get:

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

Upvotes: 0

Views: 1623

Answers (1)

Ellis Valentiner
Ellis Valentiner

Reputation: 2206

Your y variable is a character vector. R doesn't know whether NA11830 comes before or after NA12004. If you convert it to a factor, you'll get a plot.

Edit:

You can use the dotplot function in the lattice package to extend the base R graphics.

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

Upvotes: 1

Related Questions