Wednesday 5 August 2015

R: Draw a line graph


In previous post, I explained how to draw scattered graph. Creating a line graph is simple, just add type=”l” to the plot function.
> x <- c(10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
> y <- c(1, 2, 4, 6, 10, 18, 24, 34, 58, 90)
> plot(x, y, type="l")

Above statements draws a line graph like following.

You can draw the line graph, using qplot function of ggplot library also.

> qplot(x, y, geom="line")

Above statement draws line graph like following.




Prevoius                                                 Next                                                 Home

No comments:

Post a Comment