我正在處理大量 R Markdown 檔案,這些檔案共同用于使用bookdown. 對于長行代碼(將出現在書中),我一直在將其寫在靠近第 80 列的地方,此時我插入一個硬換行符,制表符(4 個空格),然后繼續代碼。這是我認為在文本中看起來不錯的(對于讀者而言)。但是,當這是(例如)函式的一部分時,我遇到了問題ggplot()。這是一個快速(無意義)的示例:
testx <- seq(1:100)
testy <- rnorm(testx)
testdat <- as.data.frame(cbind(testx, testy))
g <- ggplot(testdat, aes(x = testx/100, y = testy))
g <- g geom_point() geom_line()
g <- g labs(title = "The Posterior Distribution",
caption = "The mode and 95% HPD intervals are the dot and horizontal line at
the bottom, respectively.",
x = expression(beta[1]~(slope)))
g
在此示例中,我需要將caption()引數分成兩行,因為它很長,但我不希望它在實際標題中中斷。
有沒有辦法做到這一點?
uj5u.com熱心網友回復:
如果我理解正確,您可以使用 paste0。
caption = paste0("The mode and 95% HPD intervals are the dot",
" and horizontal line at the bottom, respectively.")
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/440273.html
