Original link:tecdat.cn/?p=13971
The R language provides rich functionality for plotting time series data in R.
Include:
- Automatically graph XTS time series objects (or any object that can be converted to XTS).
- Height configurable axis and series display (including optional second Y axis).
- Rich interactive features, including zooming/panning and series/dot highlighting.
- Displays the up/down bars around the sequence (for example, prediction interval).
- Various graphics overlay layers, including shaded areas, event lines and dot notes.
- Use it on the R console as a regular R diagram (via the RStudio Viewer).
- Seamlessly embedded into R Markdown documents and Shiny Web applications.
The installation
Line charts can be used in the R console, R Markdown documents, and Shiny applications.
Demo version
Here is a simple line chart created by multiple time series objects:
lungDeaths <- cbind(mdeaths, fdeaths)
graph(lungDeaths)
Copy the code
Please make this diagram fully interactive: when the mouse moves over the series, the individual values are displayed. You can also select the area of the graph you want to enlarge (double click to zoom out).
You can customize a chart by piping additional commands to the original chart object. Here we pass the range selection component to the original graph:
graph(lungDeaths) %>% RangeSelector()
Copy the code
This example uses the %>% (or “pipe”) operator in the Magrittr package to form a chart with a range selector. You can customize axes, series, and other options using similar syntax. Such as:
graph(lungDeaths) %>%
Options(stackedGraph = TRUE) %>%
RangeSelector(height = 20)
Copy the code
There are many options for customizing series and axis displays. Multiple families of down/value/up styles can be combined into a single display with a shaded bar.
This is an example of exponential smoothing for time series analysis, which illustrates shadowing bars, specifying graph titles, drawing grids on the X-axis, and using a custom palette for a series of colors:
graph(predicted, main = "Predicted Lung Deaths (UK)")
Copy the code
The libraries linked to from the sidebar include more examples of the various functions you can customize.
graph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
Options(stepPlot = TRUE)
Copy the code
reference
Most welcome insight
1. Dynamic map visualization in R language: how to create beautifully animated graphs
2. Visual analysis of R language survival analysis
3.Python Data Visualization – Seaborn Iris Iris data
4. R language for buffon needle throwing (Buffon needle throwing) experiment simulation and dynamic
5. Visualization case of R language survival analysis data analysis
6. R language data visualization analysis case: Explore BRFSS data data analysis
7. Dynamic visualization in R language: make animated GIF video images of cumulative dynamic line charts of historical global average temperature
8. Case report of principal component Pca and T-SNE algorithm dimension reduction and visual analysis for R language high-dimensional data
9. Python topics LDA modeling and T-SNE visualization