简体   繁体   中英

R plotting frequency distribution

I know that we normally do in this way:

x=c(rep(0.3,100),rep(0.5,700))
plot(table(x))

However, we can only get a few dots or vertical lines in the graph.

What should I do if I want 100 dots above 0.3 and 700 dots above 0.5?

Something like this?

x <- c(rep(.3,100), rep(.5, 700))
y <- c(seq(0,1, length.out=100), seq(0,1,length.out=700))
plot(x,y)

edit: (following OP's comment)

In that case, something like this should work.

x <- rep(seq(1, 10)/10, seq(100, 1000, by=100))
x.t <- as.matrix(table(x))
y <- unlist(apply(x.t, 1, function(x) seq(1,x)))
plot(x,y)

You can lay with the linetype and linewidth settings...

plot(table(x),lty=3,lwd=0.5)

在此处输入图片说明

For smaller numbers (counts) you can use stripchart with method="stack" like this:

stripchart(c(rep(0.3,10),rep(0.5,70)), pch=19, method="stack", ylim=c(0,100))

But stripchart does not work for 700 dots.


Edit:

The dots() function from the package TeachingDemos is probably what you want:

 require(TeachingDemos)
 dots(x)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM