在ggplotly中使用dynamicTicks参数时,它已删除了我感兴趣的日期范围两侧的边距。
我尝试在scale_x_date()中显式设置'expand'参数,但是我相信dynamicTicks会覆盖它。
req(data.table)
plot_data = data.table(Date = seq.Date(ymd('2018-01-01'), ymd('2019-03-01'), by = 'day'))
plot_data$Value = rnorm(n = nrow(plot_data), mean = 1000, sd = 100)
p_obj = ggplot(data = plot_data, aes(x = Date, y = Value)) +
geom_line() +
scale_x_date(expand = c(0.05,0))
# This gives does not give the 5% margin - however it does adjust the x axis as I zoom in
ggplotly(p_obj, dynamicTicks = T)
# This gives the 5% margin - however does not adjust the x axis as I zoom in
ggplotly(p_obj, dynamicTicks = F)
默认情况下,ggplot在最小和最大日期范围的任一侧都会增加5%的边距,但是,当dynmaicTicks = T时,边距为零。