labels <- c("Label1", "Label2", "Label3", "Label4", "Label5", "Label6")
colors <- c("#ff0000", "#00ff00", "#0000ff", "#ffff00", "#ff00ff", "#00ffff")
# Convert to 'unit' objects for grid
grid::grid.roundrect(
x = grid::unit(0.5, "npc"), # "npc" stands for normalized parent coordinates
y = grid::unit(0.5, "npc"),
width = grid::unit(0.1, "npc"),
height = grid::unit(0.05, "npc"),
gp = grid::gpar(fill = "red"),
r = grid::unit(0.1, "npc") # rounding radius
)
# Example of drawing legends with specific labels and colors
drawLegends(labels, colors, grid::unit(2, "cm"), c(0.225, 0.75), 0.5,
list(c("left", "center"), c("right", "center")),
list("right", "left"), 10)
Run the code above in your browser using DataLab