ggplot2:使用scale_y_continuous时plot是空的

时间:2016-11-26 04:03:19

标签: r ggplot2 scale

使用此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)

我得到了这个情节

enter image description here

这些值是汇率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))

然而,最终的情节是空的。有什么建议出了什么问题? enter image description here

2 个答案:

答案 0 :(得分:2)

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

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)

enter image description here

答案 1 :(得分:0)

您无法在不包含整个条形图的情况下绘制geom_bar。尝试使用geom_point查看您的代码是否正常,或将下限从17更改为0.