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:
然而,我想将文本左对齐到一个整洁的列中。我基本上是在问如何为text
提供xmin
。我需要对x
变量执行数学运算来相应地缩放x
吗?还是有一个theme
的技巧?