the_okay_gatsby
the_okay_gatsby

Reputation: 23

Assign value pairs for scale_color_manual and scale_shape_manual in ggplot?

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.

Upvotes: 0

Views: 1619

Answers (1)

Dan
Dan

Reputation: 1778

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)

Upvotes: 1

Related Questions