1
我想在一個圖的旁邊放置較長的文本,但是格式問題。這是主線劇情代碼:在R中繪製一個圖的文本塊
percentile.plot <- function(value = 3, rev = FALSE,
col.fade = c("snow2","snow1", "snow"),
box.lwd = 3, box.col="snow4", point.col= "black"){
x <-c(1:5)
y <- rep(1, 5)
colfunc <- colorRampPalette(col.fade)
if(rev){colors <- rev(colfunc(2000))} else { colors <- colfunc(2000) }
segm <- seq(0, 5, by = 0.005)
par(mar = c(0, 10, 0, 10))
plot(x, y, type = "n", bty="n", axes=F, ylab="", xlab="",
xlim=c(0,5), ylim=c(0,1), asp=1,
xaxs ="i", yaxs = "i")
segments(x0 = segm, y0 = 0, y1=1, x1 = segm, col= colors, lty=1.2)
segments(x0 = c(0:5), y0 = 0, y1=1, x1 = c(0:5), col= box.col, lwd=box.lwd)
segments(x0 = 0, y0 = c(0:1), y1=c(0:1), x1 = 5, col= box.col, lwd=box.lwd)
if (value >= .99) {value <- .99}
if (value < .01) {value <- .01}
value.trans <- value*5
points(x = value.trans, y = 0.5, pch=4, lwd=3, cex=1.3, col=point.col)
}
percentile.plot(0.9)
現在我想將文本塊左右的情節,這可能是這樣的:
text_left <- "I would like to put a text next to my graph \n
but unfortunately I cannot get the formatting \n
right. Either my margins are to big to knit my \n
plot into an html or the text is not aligned \n
as I want it to be. I am sure there is an easy \n
solution but I haven’t found one yet."
text_right <- "I would like to put a text next to my graph \n
but unfortunately I cannot get the formatting \n
right. Either my margins are to big to knit my \n
plot into an html or the text is not aligned \n
as I want it to be. I am sure there is an easy \n
solution but I haven’t found one yet."
我試過如下:
par(lheight = 0.5)
mtext(text_left, las = 1, side = 2, outer = TRUE, adj = 0, line= 5, cex = .8)
mtext(text_right, las = 1, side = 4, outer = TRUE, adj = 0, line= -8, cex = .8)
導致:
我想要的是劇情左邊的一個文本塊,它左側對齊,右側對齊,左側對齊。文本應該是我計算出的圖的每一端的描述。
此外,我試圖在不同的計算機(13「和27」),並不得不改變邊緣大小,以獲得相同的結果。有沒有更好的方式來添加文字到情節?此外,實際情節應該比圖片中的情節要大,但我無法正確執行此操作。
如果希望每個文本塊是在尺寸上與情節相媲美,我會建議使用'layout'或'面值( mfrow(c(1,3))'並且對每一段文本使用不同的繪圖區域和你的圖 – Gregor
同意你可能想要刪除函數中的'par'並嘗試類似'library(gplots); par = rep(0,4));佈局(矩陣(c(1,1,2,3,3),nrow = 1)); textplot(text_left,「right」,「center」); percentile.plot(0.9 );文本情節(text_left,「左」,「中心」)。 – lukeA