key_scale | R Documentation |
draw_key_polygon2()
is an extension of
draw_key_polygon()
from ggplot2
to modify the spacing between legend keys on bar graphs and other graphs
where the fill
aesthetic is used. It does this by scaling down the legend
keys within their allotted space.
key_scale(scale = 0.8)
draw_key_polygon2(data, params, size, scale = 0.8)
scale |
Scaling factor for the height and width of the legend key within its allotted space. Defaults to 0.8, which gives the key 80 percent of the allotted height and width. |
data |
A single row data frame containing the scaled aesthetics to display in this key |
params |
A list of additional parameters supplied to the geom. |
size |
Width and height of key in mm. |
key_scale()
is a wrapper function to allow the specific scaling of the
legend keys to be modified inside the geom
function.
The core part of this approach that differs from the standard ggplot2
polygon key is that the width and height are changed to unit(scale, "npc")
instead of unit(1, "npc")
, where scale
has a default value of 0.8
. This
makes the width and height of the fill key take up 80 percent (or the scale
value, if different) of the key space instead of 100 percent of the key
space. This makes the key fill slightly smaller, giving the appearance of
increased space between the keys.
A grid grob.
library(ggplot2)
df <- data.frame(
x = factor(c("IL6R", "IL8R", "IL6R-Ab", "IL8R-Ab", "IL6R-Ab-IL8R"),
levels = c("IL6R", "IL8R", "IL6R-Ab", "IL8R-Ab", "IL6R-Ab-IL8R")),
y = c(0.45, 0.78, 0.61, 0.31, 0.72))
p <- ggplot(df, aes(x, y, fill = x)) +
geom_col(key_glyph = key_scale())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.