The unit function is in the grid package. You need to explicitly download it and add to your search path using
library("grid")
As for your subsequent question in the comments, since ggplot2 needs a grid , grid was loaded when ggplot2 was loaded, and its functions were available for ggplot2 . However, it was not added to the global search path, so its functions ( grid ) were not found when you try to call them directly. A call to library() (or require() ) makes them available.
The difference between the two functions is described in their documentation.
library(package) and require(package) download a package called package . require intended to be used inside other functions; it returns FALSE and gives a warning (and not an error, as library() does by default) if the package does not exist.
and in this other question: What is the difference between require () and library ()?
source share