R绘图因子,y轴上的值

时间:2016-01-08 07:10:04

标签: r plot axis-labels

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

plot(1:9,f)

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

如何在y轴上获得f(“a”,“b”和“c”)的值?

2 个答案:

答案 0 :(得分:3)

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

R base

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

<强>晶格

see fdetsch answer

<强> GGPLOT2

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

答案 1 :(得分:1)

使用格子非常容易。

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

xyplot

相关问题