R ggplot中的左对齐刻度标记

mhe*_*ans 10 visualization r ggplot2

我可以找到将图例和轴标签对齐的选项ggplot,但不能找到刻度线标签.

是否可以将这些标签与图形图框右对齐,但是左对齐与最长标签的起点齐平,还是与整个图形边界设置一定距离?

例:

set.seed(1)
library(ggplot2)
axisLabels.x <- c("This is a longer label", 
              "Short label", "Short label","Short label","Short label",
              "This is again a longer label")
labels.wrap  <- lapply(strwrap(axisLabels.x,50,simplify=F),paste,collapse="\n") # word wrap
gg <- data.frame(x=LETTERS[1:6], y=sample(1:10,6))
ggplot(gg) +
  geom_bar(aes(x,y, fill=x), stat="identity")+
  scale_x_discrete(labels=labels.wrap)+
  scale_fill_discrete(guide="none")+
  labs(x="",y="Response")+
  coord_flip()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


通缉:

在此输入图像描述

lok*_*oki 5

由于它提供了解决方案,我将@ user20650的评论作为答案.

set.seed(1)
library(ggplot2)
axisLabels.x <- c("This is a longer label", 
                  "Short label", "Short label","Short label","Short label",
                  "This is again a longer label")
labels.wrap  <- lapply(strwrap(axisLabels.x,50,simplify=F),paste,collapse="\n") # word wrap
gg <- data.frame(x=LETTERS[1:6], y=sample(1:10,6))
plot <- ggplot(gg) +
  geom_bar(aes(x,y, fill=x), stat="identity")+
  scale_x_discrete(labels=labels.wrap)+
  scale_fill_discrete(guide="none")+
  labs(x="",y="Response")+
  coord_flip()
Run Code Online (Sandbox Code Playgroud)

现在我们开始

plot + theme(axis.text.y = element_text(hjust = 0))
Run Code Online (Sandbox Code Playgroud)

左对齐的y刻度标签