我正在向我的視覺效果添加資料標簽,每當我的值接近零時,我的資料標簽就會在 y 軸附近被切斷。請參見下圖中的示例。有沒有辦法增加 0 值和 Y 軸值之間的空間?
以下示例的代碼:
AgencyComposition <- data_frame(
Agency = c("Unassigned", "SOFTEL", "HHS", "BESTLIFE")
Users = c(1, 40, 3, 2)
)
AgencyComposition
這是視覺效果:
V_agencycomposition <- AgencyComposition %>%
ggplot(
aes(
x = Users,
y = Agency
)
)
geom_col(
aes(
fill = "Users"
),
alpha = .8
)
labs(
x = "Number of users",
y = "Agency",
color = "User count"
)
geom_label(
aes(label = Users),
hjust = 1.2
)
theme(legend.position = "bottom")
V_agencycomposition
提前致謝!

uj5u.com熱心網友回復:
你可以expand在里面使用scale_x_continuous。在這里,我使用c(0.1, 0)了 ,但如果你想在左側有更大的間隙,你可以將 0.1 設定為你喜歡的大小。
AgencyComposition %>%
ggplot(
aes(
x = Users,
y = Agency
)
)
geom_col(
aes(
fill = "Users"
),
alpha = .8
)
labs(
x = "Number of users",
y = "Agency",
color = "User count"
)
geom_label(
aes(label = Users),
hjust = 1.2
)
scale_x_continuous(
expand = c(0.1, 0)
)
theme(legend.position = "bottom")
V_agencycomposition

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/432029.html
上一篇:Rplotly顯示游標坐標
