2
ggplot2
將文本自動居中在geom_text
圖層中。例如:使用ggplot2左對齊geom_text圖層
library(ggplot2)
library(tidyverse)
df <- data_frame(text = c("A short sentence.",
"A slightly longer sentence.",
"This sentence is the longest of the sentences."),
y = row_number(text) - 1,
x = 1)
ggplot(df, aes(x = x, y = y)) +
geom_text(aes(label = text), nudge_x = nchar(text)/2)
產地:
ggplot:
不過,我要左對齊在一個整潔的列中的文本。我本質上是問如何提供xmin
到text
。我是否需要對x
變量進行數學運算,該變量相應地縮放x
?或者有一個與theme
?
又見HTTPS: //community.rstudio.com/t/how-do-i-set-an-xmin-argument-to-geom-text/785/3 – baptiste