如何在堆叠条形图上仅显示条件标签

时间:2018-08-07 18:48:27

标签: r ggplot2

我正在尝试创建条形图,并且希望仅在堆叠图上显示具有最新日期的值。我的数据框由四列组成

Date <- c("18.Jun", "18.May", "18.Apr", "18.Mar")

variable <-c("LongNetEquity","LongTotalEquity","ShortNetEquity","ShortTotalEquity","NetEquity","NetTotalEquity","GrossNetEquity","TotalNetEquity", "NetEquityPerfAttr","GrossTotalEquityPerfAttr")

value<-c(88,86,77,65,34,12,56,89)

Criteria <- c("Above 70", "Between 60 & 70", "Between 45 & 60", "Below 45")

下面是我到目前为止创建的ggplot:

ggplot() +
  geom_bar(data = era, aes(x=variable, y=value ,fill=Criteria),stat="identity", alpha = 0.7) +
  coord_flip() +
  scale_fill_manual(values=c("red3","orange3","green3","yellow3"))

我希望在此图上显示具有以下条件的标签:

label <- era[which(era$Date == "18.Jun"),]

我很感谢我得到的帮助。

谢谢

0 个答案:

没有答案