How to use custom colors

How can I use my custom colors "my_cols" within the codes extracted from

#> Loading required package: grid

my_cols <- c("Black", "Blue")

gradientPoints <- function(data, coords) {
  gradients <- lapply(data$colour,
                      function(x) {
                        radialGradient(c("white", x),
                                       cx1=.7, cy1=.7,
  pointsGrob(coords$x, coords$y, pch=21,
             gp=gpar(fill=gradients, col=NA))
gradientKey <-  function(data, ...) {
  gradient <- radialGradient(c("white", data$colour), cx1=.7, cy1=.7,
  pointsGrob(.5, .5, pch=21,
             gp=gpar(fill=gradient, col=NA))
mtcars$am <- as.factor(mtcars$am)
ggplot(mtcars) +
             mapping=aes(x=disp, y=mpg, colour=am),
             key_glyph=gradientKey, show.legend=TRUE)

The same as any ggplot, + scale_color_manual(values = my_cols).


Perfect. I never imagined it could work out. Thank you.

Any idea about changing the shape/pch to 17 or 15 both for legend and plot. Or use multiple shapes like pch = c(21, 17), or shape = c(21, 17)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.