【发布时间】:2018-02-25 19:13:42
【问题描述】:
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有什么技巧吗?
【问题讨论】: