简体   繁体   English

ggplot2 worldmap中的图例大小

[英]Legend size in ggplot2 worldmap

I am using the worldmap function from the Maps.R library. 我正在使用Maps.R库中的worldmap函数。 It runs in ggplot2. 它运行在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: 我的R终端返回:

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. 我相信这是ggplot2中调整图例大小的正确语法。

Thanks much, bfb 非常感谢,bfb

The function unit is in the grid package. 功能unit位于grid包中。 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 . 至于评论中的后续问题,由于ggplot2需要grid ,因此在加载ggplot2并且其功能可用于ggplot2ggplot2加载grid 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. 但是,它没有添加到全局搜索路径中,因此当您尝试直接调用它们时,找不到它的( grid )函数。 Calling library() (or require() ) makes them findable. 调用library() (或require() )使它们可以找到。

The difference between the two functions is described in their documentation 两个函数之间的区别在他们的文档中描述

library(package) and require(package) both load the package with name package . library(package)require(package)都使用name package加载package require is designed for use inside other functions; require设计用于其他功能; it returns FALSE and gives a warning (rather than an error as library() does by default) if the package does not exist. 如果包不存在,它返回FALSE并发出警告(而不是像library()默认执行的错误library()

and in this other question: What is the difference between require() and library()? 在另一个问题中: require()和library()有什么区别?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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