The data I have:
head(ave_temp)
date deadlift
5 2012-12-01 50
6 2013-01-01 62
7 2013-02-01 70
8 2013-03-01 70
9 2013-04-01 77
10 2013-05-01 83
from which I create a bar chart with ggplot2. To make it interactive I use ggplotly and its function rangeslider. Then I want to set slider range the way that when you load the chart the time interval you see is f. ex. a few years not all years my data have.
The result I want:
The chart my code produces:
And my code:
ave_temp <- ave[!is.na(ave$deadlift),]
g2 <- ggplot(data = NULL) +
theme_light() +
labs( y = 'Deadlift (kg)', x = 'Date') +
geom_col(data = ave_temp, aes(x = date, y = deadlift, text = paste('Deadlift: ', deadlift)), fill = "pink", alpha = 1, width =15) +
scale_x_date(date_breaks = "years" , date_labels = "%Y") +
scale_y_continuous(breaks=seq(0,150,25))
ggplotly(g2, tooltip = c("text"), dynamicTicks = T) %>%
rangeslider(borderwidth = 1, start = ave_temp$date[5], end = ave_temp$date[14])