繁体   English   中英

最小化geom_bar图的高度

[英]Minimize the height of a geom_bar plot

由于高度比其他数据点大,我有一个条形图切断数据标签。 我想调整高度,以便标签可见。

season batsman       total_runs
<int> <chr>              <int>
1   2016 V Kohli              973
2   2018 KS Williamson        747
3   2012 CH Gayle             733
4   2013 MEK Hussey           733
5   2019 DA Warner            727
6   2014 RV Uthappa           660
7   2017 DA Warner            641
8   2010 SR Tendulkar         618
9   2008 SE Marsh             616
10   2011 CH Gayle             608
11   2009 ML Hayden            572
12   2015 DA Warner            562

我试过ylim,但在我的情况下不起作用。

season_top_scorer <- match_full%>%
  group_by(season,batsman)%>%
  summarize(total_runs = sum(batsman_runs))%>%
  arrange(season,desc(total_runs))%>%
  filter(total_runs == max(total_runs))%>%
  arrange(desc(total_runs))%>%
  ggplot(aes(x = season,y = total_runs,fill = batsman))+
  geom_bar(stat ="identity")+
  ggtitle("Highest run scorer each season")+
  theme(axis.text.x = element_text(angle = 90, hjust = 1))+
  scale_x_discrete(name="Season", 
  limits = c(2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019))+
  geom_text(aes(label= total_runs,vjust= 0 ))+
  scale_y_discrete(name = "Total Runs",  limits = c(0,250,500,750,1000,1250))

唯一的问题是2016年的季节。酒吧的高度太大,以至于它切断了标签。任何想法可以在上面的代码中解决这个问题

您应该使用scale_y_continuous而不是scale_y_discrete

scale_y_continuous(name = "Total Runs", breaks = c(0, 250, 500, 750, 1000, 1250))

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM