在条形GGplot中间居中刻度和标签

时间:2019-02-08 20:04:29

标签: r ggplot2

我正在ggplot中创建条形图,但是,似乎无法使标签和刻度线位于条形图的中心。而是标签在右边。我已经尝试过碰碰碰碰,但没有帮助。

以下是图表的外观:

enter image description here

要清楚一点,我希望2019-01的标签和轴一直位于红色条的中心,一直到最右边。

以下是创建图表的代码:

ggplot(data = earnings_returns, aes(x=date, y=return, fill=factor(sign(return)))) +
  geom_col(show.legend = FALSE) +
  ggtitle(paste(ticker, 'Returns', 5, 'Day(s) After Announcement'))+
  scale_fill_brewer(palette="Set1")  + 
  theme(axis.text.x = element_text(angle = 90))

和创建数据框的代码:

earnings_returns <- structure(list(date = structure(c(17836, 17743, 17652, 17563, 
17472, 17379, 17288, 17197, 17099), class = "Date"), time = c(" AC", 
" AC", " AC", " AC", " AC", " AC", " AC", " AC", " AC"), ticker = c("AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL"
), price.close = c(222.220001, 190.289993, 169.100006, 167.779999, 
168.110001, 150.050003, 147.509995, 121.349998, 118.25), return = c(-0.0617855995779606, 
0.0883914478886969, 0.100236525124665, -0.0752771788966337, 0.0462197605959207, 
0.0668443772040446, 0.0439292944183205, 0.083889585230978, -0.0571670359408034
)), row.names = c(NA, -9L), class = "data.frame")

谢谢。

1 个答案:

答案 0 :(得分:0)

我知道了,这是使用日期的问题。更改它们以解决此问题:

enter image description here

data FeeType = FeeMarkupHidden | FeeExplicit

data Fee : (ft : FeeType) -> Type where
    HidFee : Fee FeeMarkupHidden
    ExFee : Nat {- or w/e -} -> Fee FeeExplicit

data ValidArticle : (ft : FeeType) -> Type where
    MkVA : ValidArticle ft

data ValidInvoice : (ft : FeeType) -> Type where
  MkVI : ValidArticle ft -> Fee ft -> ValidInvoice ft