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
的{{1}}变量执行数学运算?或者x
是否有诀窍?
答案 0 :(得分:9)
您可以使用(env) paper-street:CoinSlack kyle$ gunicorn -b :8000 run
[2017-09-16 17:43:59 -0700] [15402] [INFO] Starting gunicorn 19.7.1
[2017-09-16 17:43:59 -0700] [15402] [INFO] Listening at: http://0.0.0.0:8000 (15402)
[2017-09-16 17:43:59 -0700] [15402] [INFO] Using worker: sync
[2017-09-16 17:43:59 -0700] [15405] [INFO] Booting worker with pid: 15405
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
:
hjust
您还可以添加ggplot(df, aes(x = x, y = y)) +
geom_text(aes(label = text), hjust = 0)
以将列对齐到绘图的最左侧:
xlim