R Programming/ggplot

From Wikibooks, open books for an open world
Jump to: navigation, search

Plotting a function [edit]

We use qplot() with the option stat=function :

# Plot the quadratic function
square <- function(x){
  x^2
}
mode(square)
qplot(c(0, 2), stat = "function", fun = square, geom = "line")

Here is another example with the sinus function  :

# plot the sinus functon
qplot(c(-10, 10), stat = "function", fun = sin, geom = "line")

Resources [edit]