Fopa Léon Constantin
Fopa Léon Constantin

Reputation: 12363

how to plot a line chart in R?

I have data in a file, they look this way :

frame_delay
0.000030
0.000028
0.000028
0.000028
0.000028
0.000028
0.000027
0.000027
0.000027
0.000027
0.000028
0.000027
....

I wrote this R script

delays <- read.table("../../data/frame_delay.dat", header=T)
plot(delays)

And get the following chart.

enter image description here

I wonder how to tune my code to get something more readable like this (forget about lines) where y-axis represent above values and x-axis any sequence of number from 1 to whatever.

enter image description here

Thanks for any reply !

Upvotes: 1

Views: 2749

Answers (2)

bill_080
bill_080

Reputation: 4760

Try this:

delays <- read.table("../../data/frame_delay.dat", header=T)
plot(row(delays), delays[, 1], type="l")

enter image description here

Upvotes: 2

Matthew Lundberg
Matthew Lundberg

Reputation: 42649

Give it an artificial X-axis, such as this (naming your data frame x):

plot(cbind(1:length(x[[1]]), x), xlab='Index')

This does the same thing, perhaps a bit more efficiently:

plot(1:length(x[[1]]),x[[1]], xlab='Index')

Upvotes: 0

Related Questions