I know how to extract axis limits after making a plot with base
R functions.
plot(Sepal.Length ~ Sepal.Width, iris)
(Horizontal_Axis_Limits <- par('usr')[1:2])
(Vertical_Axis_Limits <- par('usr')[3:4])
There's a good answer here for ggplot2
figures, but is there a way to do this same thing when using other packages such as the dygraphs
package? I know about the valueRange
argument to the dygraphs::dyAxis()
function, but I'm not sure if I can somehow use that to extract the axis limits after the graph has already been created. Here's a reproducible example.
Time <- seq.POSIXt(as.POSIXct('2022-1-1 00:00:00'), as.POSIXct('2022-3-1 00:00:00'), by = '1 h')
Response <- sin(seq_len(length(Time)) / 100) + rnorm(length(Time), 0, 0.25)
Data_Frame <- data.frame(Time = Time, Response = Response)
Data <- xts(x = Data_Frame$Response, order.by = Data_Frame$Time)
(Figure_1 <- dygraphs::dygraph(Data))
Here's a plotly
reproducible example as well. There's a Stack Overflow answer here that gives an answer to this question for python, but it doesn't provide anything for R.
(Figure_2 <- plotly::plot_ly(ggplot2::economics, x = ~date, y = ~pop))
Thank you!