Search code examples
rggplot2scale

ggplot2: plot is empty when using scale_y_continuous


Using this data.frame

Data

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)

and this script

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)

I got this plot

enter image description here

These values are the exchange rate USD/EGP. The fluctuations in the exchange rate are between 17 and 17.45. I want to zoom in to highlight these fluctuation so I used

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

However, the final plot was empty. Any suggestion what went wrong? enter image description here


Solution

  • Line graph also show the desired zoomed variation

    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