无法在 r 中的 ggplot2 构面图中旋转 x 轴标签

Cannot rotate x axis labels in ggplot2 facet graphs in r


任何人都可以帮忙完成一项任务吗?
我一直在尝试 运行 在 r 中创建 facet_wrap() 图的代码的一部分,它对我的​​海豚非常有效,但 x 轴标签相互重叠。
我需要将它们旋转 45 度。
我一直在尝试 运行 这段代码用于海豚,它确实创建了图形,但 x 轴标签没有像我预期的那样旋转。

代码如下:

for (x in unique(clss_perc_factor7$Horto)){
  ggsave(paste('barplot_esp40', x, sep = '_'), 
         ggplot(clss_perc_factor7[clss_perc_factor7$Horto == x,], 
                aes(x = Classe, 
                    y = Freq_perc)) +
           theme(plot.title = element_text(hjust = 0.5), 
                 axis.text.x = element_text(angle = 45, hjust = 1)) +
           theme_bw() +
           geom_bar(stat = 'identity', 
                    colour = 'black', 
                    fill = '#66CC99') +
           facet_wrap(~ CD_TALHAO) +
           labs(x = 'Classe de Espaçamento', 
                y = 'Nº de Indivíduos (%)', 
                title = 'Distribuição do Espaçamento em Classes'),
         dpi = 'retina',
         device = 'png')
}

鉴于:

OBS:本应将标题居中对齐的部分 theme(plot.title = element_text(hjust = 0.5)... 也不起作用。

非常感谢你们!

这里有一个方法:

library(ggplot2)
ggplot(mtcars,aes(hp,mpg)) +
  geom_point() + 
  facet_wrap(~cyl) +
  theme(strip.text.x = element_text(angle = 45)) 

祝你好运!