Aaron
Aaron

Reputation: 1191

R - ggplot, Change base color used by aes() for coloring according to ..n

This solution doesn't work: R: ggplot heatmap color change

I use ..n.. within aes(...) to use the count a coloring criteria.

I found no way to change the default color gradient (blue to darkblue) as it would be possible if a "normal" variable instead of ..n.. is used.

Normally I'd expect something like this (below) to work. But I found no way to refer to the used ..n.. in the scale_fill_gradient(...) call.

p <- ggplot(data, aes(x=V1, y=V2))
+ geom_violin(scale="width",aes(color = ..n..))
+ scale_fill_gradient('n',limits=c(0, 100), breaks = c(0, 25, 50, 75, 100),  low = "red", high = "green")

The defalt gradient is still used instead of the defined gradient.

How can I change the gradient in use with the ..n.. critria ?

Upvotes: 2

Views: 492

Answers (1)

Yollanda Beetroot
Yollanda Beetroot

Reputation: 333

With ggplot there are two kinds of colour scale that you can specify in aes(): colour and fill. Your example does not work because you map a colour aesthetic, and specify a fill scale, two scales that are not more related to each other than the size, shape and alpha scales. One of these should work: either you do aes(fill = ..n..) or you use scale_colour_gradient().

Upvotes: 1

Related Questions