为facet_wrap标签自定义或使用另一列

时间:2018-03-30 04:27:20

标签: axis-labels facet-wrap

Image of the plot is here

Image of the data is here

我已经能够在facet_wrap标签中部署缩写的月份,但我想使用J,F,M,A,M,J,J,A,S,O,N,D类标签。我的代码如下。

   ggplot(sr3, aes(x=Month2, fill = Year)) +  geom_bar() + 
   theme(axis.text.x = element_text(angle = 90, hjust = 1)) + 
   facet_wrap(~Province) +
   labs(title ="US Drone Strikes in Afghanistan from Jan 2015- Mar 2018", 
   x = "Monthly distribution across Provinces", y = "No. of Strikes")

1 个答案:

答案 0 :(得分:0)

试试这个,它应该与因子一起使用:

   ggplot(transform(sr3, Month2=factor(Month2, levels=c("J","F","M",......))),aes(x=Month2, fill = Year)) +  geom_bar() + 
   theme(axis.text.x = element_text(angle = 90, hjust = 1)) + 
   facet_wrap(~Province) +
   labs(title ="US Drone Strikes in Afghanistan from Jan 2015- Mar 2018", 
   x = "Monthly distribution across Provinces", y = "No. of Strikes")