我有以下ggplot
library(ggplot2)
library(scales)
df <- data.frame("levs" = c("a long label i want to wrap",
"another also long label"),
"vals" = c(1,2))
p <- ggplot(df, aes(x = levs, y = vals))
geom_bar(stat = "identity")
coord_flip()
scale_x_discrete(labels = wrap_format(20))
有了這個,我得到了以下情節

我想知道我是否可以分別在最左邊left align和right align最右邊tick labels(即 0.0 和 2.0)。基本上在我的實際情節中,我在這兩個地方都有很大的負數和正數,它們溢位了情節區域。
任何輸入都非常有幫助。
uj5u.com熱心網友回復:
您可以指定不同hjust()的theme()
代碼
library(ggplot2)
ggplot(df, aes(x = levs, y = vals))
geom_bar(stat = "identity")
coord_flip()
scale_x_discrete(labels = wrap_format(20))
scale_y_continuous(breaks = seq(-20000, 20000, by = 10000))
theme(axis.text.x = element_text(hjust=c(0, 0.5,0.5,0.5, 1)))
輸出

資料
df <- data.frame("levs" = c("a long label i want to wrap",
"another also long label"),
"vals" = c(-20000,20000))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/450746.html
