-1

image

I have plotted a signal sampled at 20Hz and length of signal is 3940 (197 seconds) I want to modify the x-axis such that instead of showing limits from 0-3940 it shows 0-197s

mischva11
  • 2,811
  • 3
  • 18
  • 34
  • please add a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so we can try out your code or make improvements. Also you could just recalculate the Data before plotting it. If 3940 = 197 just calculate it and then Plot it. – mischva11 Oct 29 '18 at 14:08
  • I have a signal of 197second which is sampled at 20Hz sampling rate so it has 3940 value, when I plot the time is in (Second*20), I just want to divide the X-Axis values by 20 so I get the same plot but with new x-axis i.e. in seconds. – Yasir Ahmed Pirkani Oct 29 '18 at 16:05

1 Answers1

1

First you need to plot your data without x-axis then you can add a custom one. refer to this question If your data is named df you can use:

plot(1:nrow(df), xaxt = "n", xlab='Axis Title')
axis(1, at=1:10, labels=seq(0, 197, by=nrow(df)/198)

If instead you have a vector you should use:

plot(1:length(df), xaxt = "n", xlab='Axis Title')
axis(1, at=1:10, labels=seq(0, 197, by=length(df)/198)
gaut
  • 5,771
  • 1
  • 14
  • 45
  • 2
    I tried changing the axis i.e. plot(1:10, xaxt = "n", xlab='Some Letters') axis(1, at=1:10, labels=letters[1:10]) – Yasir Ahmed Pirkani Oct 29 '18 at 16:06
  • see edits: you have to use `nrow(df)` if you have a `data.frame` or `length(vec)` if you have a vector. It would be easier to help you if you share your current code by editing your question. – gaut Oct 29 '18 at 16:10