简体   繁体   中英

Legend size in ggplot2 worldmap

I am using the worldmap function from the Maps.R library. It runs in ggplot2.

I would like to make the legend a bit larger. I am using

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

My R terminal returns:

could not find function "unit"

Any clue as to what's going on here? I believe this to be the correct syntax in ggplot2 to adjust legend size.

Thanks much, bfb

The function unit is in the grid package. You need to explicitly load it and add it to your search path with

library("grid")

As to your followup question in the comments, since ggplot2 needs grid , grid was loaded when ggplot2 was loaded and its functions were made available to ggplot2 . However, it was not added to the global search path so its ( grid 's) functions are not found when you try to call them directly. Calling library() (or require() ) makes them findable.

The difference between the two functions is described in their documentation

library(package) and require(package) both load the package with name package . require is designed for use inside other functions; it returns FALSE and gives a warning (rather than 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()?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM