0

I successfully removed unwanted dates in a plot using the 'bdscale' packaget that were causing a known smooth curve to render in a jagged fashion due to weekends and holidays being accounted for on the x-axis. See ggplot2: remove blank space for weekends and holidays from x-axis dates. However, now my Dates no longer render correctly. I am certain there is an easy fix, but the solution escapes me. Any assistance is greatly appreciated.

The csv file is located at my github site https://github.com/123blee/123blee.github.io/blob/main/data1.csv and I call the dataframe 'xxx' in the code.

enter image description here


library(plotly)
library(bdscale)
library(scales)

# Data file - https://github.com/123blee/123blee.github.io/blob/main/data1.csv
# https://stackoverflow.com/questions/32893176/ggplot2-remove-blank-space-for-weekends-and-holidays-from-x-axis-dates
  
  ggplotly(
    ggplot(data = xxx, aes(x = Date)) + 
      geom_line(aes(y = a), color = "blue") + 
      geom_line(aes(y = b), color="black") +
      theme(panel.grid.minor = element_line(colour="white", size=0.2)) +
      scale_x_bd(business.dates=xxx$Date, max.major.breaks=10) +  
      ylim( 10, 25 )  
    
  )
   

123blee
  • 87
  • 1
  • 7

1 Answers1

0

I deciphered the issue. The 'xxx' tibble's Date column was in 'dttm' format. Adding the below single line of fixed the issue.

xxx$Date <- as.Date(xxx$Date)

enter image description here

123blee
  • 87
  • 1
  • 7