如何修复Geom_label

问题描述 投票:0回答:1

这里有一些数据

library(ggplot2) df <- structure(list(date = structure(c(18851, 19958, 18933, 18949, 18976, 19074, 19304, 19570, 19713, 19766, 20032), class = "Date"), event = c("Census data released", "Johnson v. WEC filed in state court", "People's Map Commission releases final proposal", "Gov. Evers vetoes maps", "SCOWIS receives proposed maps", "SCOTUS rules Evers' map unconstitutional", "Election held using legislature's map", "Protasiewicz begins term", "SCOWIS strikes down existing maps & invites proposals", "Legislature passes Evers' map", "Election held using Evers' map" )), row.names = c(NA, -11L), class = c("tbl_df", "tbl", "data.frame" ))
我像这样绘制它。
df |> ggplot(aes(x = 0, y = date)) + geom_line() + geom_point() + ggrepel::geom_label_repel(aes(label = str_wrap(event, 30)), hjust = -0.2, direction = "y", seed = 3)

notice标签的第二行是如何与第一行文本不一致的不一致的。 example image如何使包装标签的后续行以与标签的第一行相同的理由开头? 注:为了清楚起见,我使用

ggrepel::geom_label_repel

,但是用

ggplot2::geom_label

表示相同的包装行为。

hjust
在[0,1]之外的值不得到正式支持(AFAIK),并且可能导致怪异,例如在这种情况下。使用
hjust = 0

,然后使用例如
r ggplot2
1个回答
0
投票
将位置推向右侧的位置,或调整这些参数以获取您想要的东西。

df |> ggplot(aes(x = 0, y = date)) + geom_line() + geom_point() + ggrepel::geom_label_repel( aes(label = str_wrap(event, 30)), hjust = 0, nudge_x = 1, direction = "y", seed = 3 )


    


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.