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