在 ggplot 中将 x 轴标签向内定向

Have x-axis labels directed inwards in ggplot

我试图让 x 轴标签("Text 1" 到 "Text 6")向内移动。我希望 "Text 1" 向右对齐,这样这个标签就不会在 x = 0 之前开始。同样,我希望 "Text 6" 向左对齐,这样这个标签就在 x = 之前结束6(现在它甚至还没有完全可见)。

d=data.frame(x=c(1,2,3,4,4,6), y=c(3,7,1,4,5,6))

lbl <- paste("Text",seq(1,6,1))
ggplot() + geom_point(data=d, mapping=aes(x=x, y=y)) +
  scale_x_continuous(expand=c(0,0),labels=lbl,breaks=seq(1,6,1))

有什么建议吗?

不确定 "hacky" 这是怎么回事,但一种方法是指定 hjust:

ggplot() + 
geom_point(data=d, mapping=aes(x=x, y=y)) + 
scale_x_continuous(expand=c(0,0), labels=lbl, breaks=seq(1,6,1)) + 
theme(axis.text.x=element_text(hjust=seq(from=0,to=1,length.out=6)))