我確實找到了一種使用低級圖形參數(即「usr」,繪圖區域的實際用戶座標以及「cxy」,字符大小)獲取所需點圖的方法。在調整圖形大小時,recordGraphics()
函數會封裝需要更改的部分。這裏的功能:如果你想點之間更緊密或鬆散的差距
dot.plot = function(x, pch = 16, bins = 50, spacing = 1, xlab, ...) {
if(missing(xlab))
xlab = as.character(substitute(x))
# determine dot positions
inc = diff(pretty(x, n = bins)[1:2])
freq = table(inc * round(x/inc, 0))
xx = rep(as.numeric(names(freq)), freq)
yy = unlist(lapply(freq, seq_len))
# make the order of the dots the same as the order of the data
idx = seq_along(x)
idx[order(x)] = idx
xx = xx[idx]
yy = yy[idx]
# make a blank plot
plot(xx, yy, type = "n", axes = FALSE, xlab = xlab, ylab = "")
# draw scale
axis(1)
ylow = par("usr")[3]
abline(h = ylow) # extend to full width
# draw points and support resizing
recordGraphics({
yinc = 0.5 * spacing * par("cxy")[2]
points(xx, ylow + yinc * (yy - .5), pch = pch, ...)
},
list(),
environment(NULL))
invisible()
}
的spacing
參數可以使用。一個例子...
with(iris, dot.plot(Sepal.Length, col = as.numeric(Species)))

這是不是試圖用文字做一個更好的解決方案,也有點嚇人,因爲你的文檔中看到recordGraphics
來源
2015-04-16 21:12:39
rvl
的警告你不能用'points()'添加點到一個圖表嗎?沒有真正的陰謀「字體」。沒有代碼或數據,這真的不是一個我們可以提供幫助的編程問題。 – MrFlick
@MrFlick - 不,因爲點之間的間距取決於圖的垂直尺寸。正如我試圖解釋的那樣,無論縮放比例如何,我都希望這些點的字符寬度是分開的。 – rvl