Legend size in ggplot2 worldmap

I use the worldmap function from the Maps.R library. It works in ggplot2.

I would like to make the legend a little bigger. I use

theme(legend.key.size = unit(measure, "units")) 

My R terminal returns:

 could not find function "unit" 

Any hint of what's going on here? I believe this is the correct syntax in ggplot2 for setting legend size.

Thanks a lot, BFB

+4
source share
1 answer

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 ()?

+4
source

All Articles