如何在R中绘制堆积点图?

时间:2013-03-06 10:35:48

标签: r graphics plot

这是一个情节,我怎么能用R画出来?

enter image description here

3 个答案:

答案 0 :(得分:21)

基本R函数是stripchart最小的例子一个成功的例子:

set.seed(1); A <- sample(0:10, 100, replace = TRUE)
stripchart(A, method = "stack", offset = .5, at = .15, pch = 19, 
           main = "Dotplot of Random Values", xlab = "Random Values")

enter image description here

您还可以使用offset来增加堆叠点之间的差距,还可以使用pch来更改点类型。

答案 1 :(得分:7)

library(ggplot2)
ggplot(mtcars, aes(x = mpg)) + geom_dotplot()

答案 2 :(得分:-1)

这里的FYI是y轴点图的一个例子:

downv<- data.frame(
y<- c(rep(3,14),6,6,9,9,9,9,9.5,9.5,10.5,10.5,10.5,10.5,rep(11,8)),
l2<- c(rep(8,4),rep(6,6),4,4,8,8,8,4,rep(6,6),8,8,4,4,rep(6,8)),
l<- c(rep(0,7,),rep(1,7),0,1,0,0,1,1,0,1,0,0,1,1,rep(0,4),rep(1,4))
)

ggplot(downv, aes(x = factor(l), y = y, fill = factor(l2))) +
  geom_dotplot(binaxis = "y", stackdir = "center", position = "dodge", dotsize=3,  stackratio = .7) + 
scale_fill_manual(values=c("black", "black", "black"))


#need square aspect ratio