2013-01-18 130 views
1

我知道,我們通常這樣做:[R繪製頻率分佈

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

但是,我們只能得到圖中的幾個點或垂直線。

如果我想要0.3以上的100個點和0.5以上的700個點,我該怎麼辦?

+0

你的意思,而不是從(0.5,0)行至(0.5, 700)你想要700個點,而不是從(0.3,0)到(0.3,100)的線你想要100個點? – Spacedman

回答

0

是這樣的嗎?

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) 

編輯:(以下OP的評論)

在這種情況下,這樣的事情應該工作。

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) 
+0

是的,但實際情況會更復雜。 x將是一個包含很多數值的向量。我想繪製點的頻率(如果0.1發生100次,繪製100點0.1以上) – Cathy

+0

非常感謝!它的工作:) – Cathy

+0

@Cathy與plot(table(x),lwd = 6)有什麼不同? – agstudy

0

您可以用linetypelinewidth設置打下...

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

enter image description here

+1

@阿倫是... ...如何區分100和30 ..或500點...視覺上(假設點是相同的形狀,沒有抖動選項,沒有aplha混合)。 – agstudy

+0

我以爲和以前的研究一樣。但我認爲它會更好看是數字匹配頻率/ \/\ 感謝您的幫助 – Cathy

0

對於較小的數字(數),可以使用stripchartmethod="stack"這樣的:

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

但s tripchart不適用於700個點。


編輯:

從包裝TeachingDemosdots()功能可能是你想要什麼:

require(TeachingDemos) 
dots(x)