R is an amazing language. It is one of the best tools to do statistical analysis. It is very powerful and it is also free! There is a large community using R hence it has many libraries. To start off let’s see how to plot a sine wave in R. This is equivalent to printing Hello world in other programming languages.
Let t indicate time
t=seq(0,10,0.1)
The above code generates a vector t with values starting from 0 and going up to 10 in the steps of 0.1.
y=sin(t)
plot(t,y,type="l", xlab="time", ylab="Sine wave")
Here y gets the value of sine of t. The plot command plot y vs t. The default plot is point plot, so we need to specify type=“l” to make it line plot.
To get a better looking plot you can use ggplot2 library.
library(ggplot2)
qplot(t,y,geom="path", xlab="time", ylab="Sine wave")