0

I would like to know if it's possible to specify which values in scale_shape_manual(values = c(19,43,17)) get mapped to the shape aesthetic. So, I'd like to specify which value gets assigned shape 19, rather than having it done for me.

The issue that I am experiencing is that this data is being filtered in PowerBI, and sometimes shape (or color) classes get wiped out entirely, meaning that in the newly rendered visual the shapes and colors could represent different classes than they did before. For instance, if classes are A, B, and C, and the shapes are c(19,43,17) in the initial visual and I filter out class B, class C will now have shape 43 instead of 17.

If I could assign which classes get which shapes and colors, I could avoid this issue. I'd be happy to elaborate further if needed.

  • 2
    You need to provide [a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). – alistaire Mar 03 '17 at 21:59
  • 1
    It sounds like a named vector is what you need: `scale_shape_manual(values=c("A"=19, "B"=43, "C"=17))`, and similarly for colors. – eipi10 Mar 03 '17 at 23:54
  • If you have lots of values to assign, there are ways to create the named vector with less code. For example, if your data frame is called `df` and the column mapped to shape is called `group`, then you could do: `scale_shape_manual(values=setNames(c(1,4,5,10,19,43,17), sort(unique(df$group))))`. – eipi10 Mar 04 '17 at 00:01
  • This is exactly what I needed - Thank you. – the_okay_gatsby Mar 06 '17 at 15:04

1 Answers1

1

You can use:

scale_shape_manual(values = c("first"=19, "second"=43, "third"=17))

or even:

colors <- c("red", "blue", "green")
names(colors) <- letters[1:3]
scale_colour_manual(values = colors)
Dan
  • 1,711
  • 2
  • 24
  • 39