0
votes

ggplot lets me control the position of my x-axis labels and breaks in x-axis but when I pass the ggplot object to ggplotly function, the resulting plotly object loses the formatting.

library(plotly)

df <- data.frame(
Date = seq(as.Date("2017-01-01"), as.Date("2020-01-01"), by = 30),
Value = rnorm(37)
)

p1 = ggplot(df) + geom_point(aes(x=Date, y = Value)) + 
scale_x_date(position = "top", date_breaks = "1 year", date_minor_breaks = 
"3 months")

ggplotly(p1)

With the code mention above the x-axis values are still plotted at the bottom in ggplotly plot and also the break lines every 3 months are not shown.

1

1 Answers

1
votes

You could try this:

f <- list(
side = "top"
)

ggplotly(p1) %>% layout(xaxis = f)

enter image description here