需要創建一個圖表,看起來像這樣: 如何繪製在一條垂直線上點的中位值控制圖中的R
我幾乎沒有,只是缺少其垂直繪製的各個點。
這裏的數據:
q6 <- structure(list(x1 = c(0.0629, 0.063, 0.0628, 0.0634, 0.0619,
0.0613, 0.063, 0.0628, 0.0623, 0.0631, 0.0635, 0.0623, 0.0635,
0.0645, 0.0619, 0.0631, 0.0616, 0.063, 0.0636, 0.064, 0.0628,
0.0615, 0.063, 0.0635, 0.0623), x2 = c(0.0636, 0.0631, 0.0631,
0.063, 0.0628, 0.0629, 0.0639, 0.0627, 0.0626, 0.0631, 0.063,
0.063, 0.0631, 0.064, 0.0644, 0.0627, 0.0623, 0.063, 0.0631,
0.0635, 0.0625, 0.0625, 0.0632, 0.0629, 0.0629), x3 = c(0.064,
0.0622, 0.0633, 0.0631, 0.063, 0.0634, 0.0625, 0.0622, 0.0633,
0.0633, 0.0638, 0.063, 0.063, 0.0631, 0.0632, 0.063, 0.0631,
0.0626, 0.0629, 0.0629, 0.0616, 0.0619, 0.063, 0.0635, 0.063),
x4 = c(0.0635, 0.0625, 0.0633, 0.0632, 0.0619, 0.0625, 0.0629,
0.0625, 0.063, 0.0631, 0.0635, 0.0627, 0.063, 0.064, 0.0622,
0.0628, 0.062, 0.0629, 0.0635, 0.0635, 0.062, 0.0619, 0.0631,
0.0631, 0.0626), x5 = c(0.064, 0.0627, 0.063, 0.0633, 0.0625,
0.0628, 0.0627, 0.0627, 0.0624, 0.063, 0.0633, 0.0629, 0.063,
0.0642, 0.0635, 0.0629, 0.0625, 0.0628, 0.0634, 0.0634, 0.0623,
0.0622, 0.063, 0.0633, 0.0628)), .Names = c("x1", "x2", "x3",
"x4", "x5"), class = "data.frame", row.names = c(NA, -25L))
下面是代碼:
range_span <- function(x) return(diff(range(x))) # function to calculate range
# q6 <- read.table(file="/Users/.../blah.csv",header=T,sep=",") #data
medians <- apply(q6,1,median)
ranges <- apply(q6,1,range_span)
centre <- mean(medians) #grand median
Rtilde <- median(ranges) #median of ranges
plot(medians, type="b",xaxp=c(1, 25, 24),pch=19,xlab="Sample No.",ylab="Medians",main="Median Chart for Thickness of Metal Parts")
# code below draws the control limits
action.limits<-c(centre+0.681*Rtilde,centre-0.681*Rtilde)
warn.limits<-c(centre+(2/3)*0.681*Rtilde,centre-(2/3)*0.681*Rtilde)
abline(h = centre, lty = 3, col = "black")
v0 <-c("CL")
mtext(side = 4, text = v0, at = centre, col = "black", las=2)
abline(h = warn.limits, lty = 3, col = "blue")
v1 <-c("UWL","LWL")
mtext(side = 4, text = v1, at = warn.limits, col = "blue", las=2)
abline(h = action.limits, lty = 3, col = "black")
v2 <-c("UCL","LCL") # the labels for action.limits
mtext(side = 4, text = v2, at = action.limits, col = "black", las=2)
我敢肯定有一個簡單的解決方案,我沒有經歷過與RI都只是想給自己設定通過在課程作業中生成圖表來實現挑戰,但現在我開始耗盡時間。
- 請問
points()
有幫助嗎?我需要R認識到q6中的每一行都是我可能做到的樣本points(q6,c(1:25))
或類似的東西?
使用,請發表您的最小重複的例子, 'dput()'參見:[如何創建一個最小,完整和可驗證的示例](http://stackoverflow.com/help/mcve)。 –
@EricFail啊,我現在明白了。感謝編輯。 – CanofDrink
不客氣。我對你的期望行爲還是有點不清楚。你能否以某種方式說明 - 或解釋 - 你究竟在看什麼樣的情節? –