在cowplot/ 中add_sub,如何對齊多個文本標簽?這是下面的代碼。謝謝!
library(ggplot2)
library(cowplot)
p1 <- ggplot(mtcars,aes(mpg,disp))
geom_line(colour="blue")
theme_half_open()
p1_1 <- add_sub(p1,"this is an annotation.\n
Annotations can span multiple lines.",
color="red",size=14,
vpadding = grid::unit(0.5,"lines"),
lineheight = 0.5,
x=0.3,y=0.4)
ggdraw(p1_1)

uj5u.com熱心網友回復:
這將變得相當接近,盡管第二行在注釋之前有一個額外的空間存在問題。
p1_1 <- add_sub(p1,str_replace_all("this is an annotation.\n
Annotations can span multiple lines.", "\\h ", " "),
color="red",size=14,
vpadding = grid::unit(0.5,"lines"),
lineheight = 0.5,
x=0,
y=0.4,
hjust = 0)
ggdraw(p1_1)

但是,如果您已經包含換行符,那么您可以將文本保留在一起。
p1_1 <- add_sub(p1,"this is an annotation.\n\nAnnotations can span multiple lines.",
color="red",size=14,
vpadding = grid::unit(0.5,"lines"),
lineheight = 0.5,
x=0,
y=0.4,
hjust = 0)
ggdraw(p1_1)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/371939.html
