ggplot2 长 x 轴变量名称 - 重新对齐图

ggplot2 long x-axis variable names - re-aligning the plot

我正在使用 ggplot2 制作条形图。代码如下:

 ggplot(rt5, aes(x = reorder(Retweet, -Freq), y = Freq, fill = Retweet)) +       geom_bar(stat = "identity") +
      xlab("Top 5 Retweets of KKRiders") +
      ggtitle("Top 5 Retweets of KKRiders \n first three days") + coord_flip() +
      scale_x_discrete(labels = function(x) str_wrap(x, width = 5)) +
      geom_text(aes(label=Freq), vjust = 1, colour = "white") + guides(fill = FALSE) +
      theme(axis.text.x = element_text(hjust = 0)) +
      theme(plot.title=element_text(size = rel(1.2), lineheight = 1, face = "bold"))

然而,由于我的 x 轴变量标签非常长,因此图表看起来像这样。

如何减小绘图大小并使我的 x 轴标签更具可读性?我可以将图的大小减少一半,为 x 轴标签留出足够的空间吗?

可重现代码如下:

  rt5 <- structure(list(Retweet = structure(c(1L, 2L, 3L, 4L, 5L), .Label = c(

 "RT @KKRiders On another note that makes 10 IPL victories in a row And we are hungry to #Go4More#KKR",
 "RT @KKRiders Yaaayy Were now the biggest IPL team on Instagram Thanks for  all your love Knight Riders #Go4More httptcoSamtCajmIk",
 "RT @RCBTweets Dazzling hitting from Surya Kumar Yadav He builds on Gambhirs 50 to hand @KKRiders a 7 wkt win in the big 2015 #PepsiIPL O",
 "RT @DabbooRatnani Congratulations @iamsrk @KKRiders Great Win last night and an amazing start to the #IPL season #AbRamAtEden",
 "RT @t2telegraph Little AbRam makes his #EdenGardens debut at @IPL 8s opening match between @KKRiders amp @mipaltan #IPL @iamsrk httptc"),
 class = "factor"), 
 Freq = c(334L, 203L, 153L, 149L, 100L)), .Names = c("Retweet", 
 "Freq"), row.names = c(1L, 2L, 3L, 4L, 5L), class = "data.frame")

您的标签看起来像那样并不是因为 space 不够用,而是因为 str_wrapwidth=5 的用法强制换行。 而是使用

scale_x_discrete(labels = function(x) str_wrap(x, width = 25)) +

你会没事的: