ggplot2:使用 scale_y_continuous 时绘图为空

ggplot2: plot is empty when using scale_y_continuous

使用这个 data.frame

数据

banks <- read.table(text = c("
Date    Central_Bank    Al-Ahli CIB Arab_African_Bank   Misr    AbuDhabi    Qahira  Credit_Agricole Albarakah   Alt3meer_El_Eskan
20/11/2016  17.14   17.27   17.25   17.3    17.28   17  17.28   17.25   17.35   17
                            21/11/2016  17.39   17.25   17.15   17.3    17.25   17.2    17.25   17.25   17.31   17.1
                            22/11/2016  17.29   17.4    17.25   17.37   17.41   17.25   17.25   17.3    17.43   17.3
                            23/11/2016  17.3    17.4    17.3    17.32   17.41   17.3    17.3    17.25   17.35   17.25
                            24/11/2016  17.37   17.4    17.3    17.4    17.41   17.4    17.3    17.25   17.4    17.25"
                            ), header = T)

和这个脚本

banks$Date <-  as.Date(banks$Date, format="%d/%m/%Y")

banks1 <- banks %>% 
  tidyr::gather("Bank", "Value", 2:11)


ggplot(banks1, aes(x = Date, y = Value, fill =Bank))+
  geom_bar(stat= "identity", position = "dodge", fill = "Blue")+
  facet_wrap(~Bank)

我得到了这个情节

这些值是汇率USD/EGP。汇率的波动在17和17.45之间。我想放大以突出显示这些波动,所以我使用了

  scale_y_continuous( limits = c(17, 17.5), 
                      breaks=c(17, 17.1,17.2, 17.3, 17.4, 17.5))

然而,最后的情节是空的。有什么建议出了什么问题吗?

如果不包括整个柱状图,您就无法绘制 geom_bar。尝试使用 geom_point 查看您的代码是否正常,或者将您的下限从 17 更改为 0。

折线图还显示了所需的缩放变化

ggplot(banks1, aes(x = Date, y = Value, fill = Bank))+
geom_line(stat= "identity", color = "Blue", size = 2)+
scale_y_continuous( limits = c(17, 17.5),
                      breaks=c(17, 17.1,17.2, 17.3, 17.4, 17.5)
                      )+
facet_wrap(~Bank)