I am drawing DAGs in R using ggdag
and I would like to change the size of the legend key without changing the size of the DAG nodes.
The theme()
argument legend.key.size
appears to control the size of an invisible box around the legend key, but doesn't affect the actual key size, as illustrated by the code below.
ggdag::confounder_triangle() %>%
ggdag::node_status() %>%
ggplot(aes(x=x,y=y, color = status))
geom_dag_point()
theme(legend.key.size = grid::unit(3, 'cm'))
The key size appears to respond to the size
argument in geom_dag_point()
, as illustrated with this code:
ggdag::confounder_triangle() %>%
ggdag::node_status() %>%
ggplot(aes(x=x,y=y, color = status))
geom_dag_point(size = 4)
Is it possible to change the key size without changing the node size?
CodePudding user response:
You can change the size
of the color
with the guide_legend
by the same override.aes
argument in your guides
. You can use the following code:
library(ggdag)
library(ggplot2)
ggdag::confounder_triangle() %>%
ggdag::node_status() %>%
ggplot(aes(x=x,y=y, color = status))
ggdag::geom_dag_point()
guides(color = guide_legend(override.aes = list(size = 2)))
Created on 2022-07-14 by the reprex package (v2.0.1)