y 轴上具有值的 R 绘图因子

R plotting factor with values on y-axis

f <- as.factor(sample( rep(c("a", "b", "c"), 3)))

plot(1:9,f)

在 y 轴上给出值 1.0..3.0。

如何获取 f("a"、"b" 和 "c")在 y 轴上的值?

使用lattice非常简单。

library(lattice)
xyplot(f ~ 1:length(f))

f <- as.factor(sample( rep(c("a", "b", "c"), 3)))

R基

plot(1:9, f, yaxt = "n")
axis(2, 1:3, levels(f))

格子

see fdetsch answer

ggplot2

library(ggplot2)
qplot(seq_along(f), f)