- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# How to create a plot in base R with dates sequence on X-axis?

If we have a vector that contains dates as sequence that needs to be plotted on the X-axis and another vector for the response then the plot can be simply created by using the plot function. In the plot function, we would need to pass the dates as the first argument and the response vector as the second argument. Check ou the examples below to understand how it works.

## Example

x<-rpois(10,5) x

## Output

[1] 4 7 4 4 6 4 3 4 9 5

## Example

dates<-seq(as.Date("25/11/2020",format="%d/%m/%Y"),by="days",length=length(x)) dates

## Output

[1] "2020-11-25" "2020-11-26" "2020-11-27" "2020-11-28" "2020-11-29" [6] "2020-11-30" "2020-12-01" "2020-12-02" "2020-12-03" "2020-12-04"

## Example

plot(dates,x)

## Output

## Example

y<-sample(0:9,10,replace=TRUE) dates<-seq(as.Date("01/01/2020",format="%d/%m/%Y"),by="days",length=length(x)) plot(dates,y)

## Output

- Related Articles
- How to create a plot with tick marks between X-axis labels in base R?
- How to create a plot with reversed Y-axis labels in base R?
- How to display X-axis labels with dash in base R plot?
- How to display raise to the power on X-axis in base R plot?
- How to create bar plot in base R with different limits for Y-axis?
- How to display X-axis labels inside the plot in base R?
- How to display superscript for X-axis title in base R plot?
- How to change the position of X-axis in base R plot?
- How to plot values with log scales on x and y axis or on a single axis in R?
- How to plot data against specific dates on the X-axis using Matplotlib?
- How to create a bar plot using ggplot2 with percentage on Y-axis in R?
- How to create a plot of quadratic regression with fitted values against X in base R?
- How to create a plot with dashed regression line in base R?
- How to change the axis color in base R plot?
- How to use mtext function to create the X-axis labels in base R?

Advertisements