避免使用plot.factor和boxplot的最佳方法

时间:2015-09-29 04:16:54

标签: r plot

我有以下数据集

d <- data.frame(value = rep(c(120,110,100,90,80),2), 
                group = c(rep("test1",5),rep("test2",5)),
                g.num = c(rep(1,5),rep(2,5)))

d$group <- factor(d$group)

当我运行以下代码plot(d$group, d$value, type="p")时,我得到:enter image description here

但我不想要一个箱形图,我想要这样的东西: enter image description here

我用来生成上图的代码

 plot(d$g.num, d$value, type="p", axes = FALSE, xlab = "", ylab = "")
 axis(1, 1:2, levels(d$group))
 axis(2)

我的问题的根源是当你将一个因子传递给绘图函数时,使用plot.factor方法,它生成一个boxplot。考虑到这一点,什么是好的工作?最后一件事,当这个变量是一个字符而不是一个因素时,我确实在d$group上运行了plot命令。然而,这产生了相同的结果。

最后,我理想地喜欢使用基本图形的答案。但是,如果可以使用其他图形包轻松完成,则可能很有用。

谢谢!

1 个答案:

答案 0 :(得分:2)

将我的评论移至答案。您可以直接使用plot.default()来避免使用箱线图。

plot.default(d$group, d$value, type="p")