library(ggplot2)
# Points get lost in legend - make them bigger
ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) +
geom_point(size = 1) +
legend_keys(size = 4)
# Remove transparency from legend
ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) +
geom_point(alpha = 0.3, size = 3) +
legend_keys(alpha = 1)
# Change shape using name
ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) +
geom_point(size = 3) +
legend_keys(shape = "square")
# Filled shape with white fill and colored outline (shapes 21-25)
# Works because we set fill to a static color (white)
ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) +
geom_point(size = 3) +
legend_keys(shape = "circle_filled", fill = "white", stroke = 1.5)
# Colored fill with black outline - MUST map both color AND fill in the plot
# This is a ggplot2 limitation: override.aes can only set static values,
# it cannot make fill "inherit" from color
ggplot(mtcars, aes(mpg, wt, color = factor(cyl), fill = factor(cyl))) +
geom_point(size = 3, shape = 21, stroke = 1) +
legend_keys(colour = "black", stroke = 1)
# Apply to fill aesthetic (e.g., for boxplots)
ggplot(mtcars, aes(factor(cyl), mpg, fill = factor(cyl))) +
geom_boxplot(alpha = 0.5) +
legend_keys(alpha = 1, aesthetic = "fill")
Run the code above in your browser using DataLab