Home > Mobile >  Linear graphics
Linear graphics

Time:05-14

I have a dataset in this way:

maximum <- c(10) #for each time
minim <- c(2) #for each time
Quantity c(4, 2, 10, 2, 10, 6, 2)

How can I structure my dataset to create a linear graphic like this? Time is always constant except when you go from 2 to 10 (they are at the same instant)

enter image description here

CodePudding user response:

Using base R plot functions, just create a Time vector (x-axis):

maximum <- c(10) #for each time
minim <- c(2) #for each time
Time <- c(1, 2, 2, 3, 3, 4, 5)
Quantity <-c(4, 2, 10, 2, 10, 6, 2)

plot(Time, Quantity, type = "l", col = "lightblue", xaxt = "n")
abline(h = maximum, col = "darkblue")
abline(h = minim, col = "orange")

enter image description here

  • Related