0

I created a violin plot in R, and I want to change part of the dots color and size. This change will be according to an attribute of True/False in the data file.

This is how I tried it:

p <- ggplot(data, aes(order,count),levels=data_levels) +
geom_point(aes(colour = actor(data$color)))+ 
geom_violin(draw_quantiles = c(0.5),adjust = 2,size =0.4)+ 
geom_jitter(height = 0, width = 0.1,size =0.6)+ 
coord_flip()

boolColors <- as.character(c("False"="black", "True"="red")) 
boolScale <- scale_colour_manual(name="color", values=boolColors)
p1 <- p + boolScale 

I tried changing the size with scale_size_manual but it didn't work.

Chandan Rai
  • 9,879
  • 2
  • 20
  • 28
  • 1
    You haven't provided an extract of your data nor what your actor() function does, so we can't run this code extract. Even so, one error stands out - in the aesthetic for the first geom_point you set `colour = actor(data$color)`. Refer to the column `color` directy, so remove the data$ part - `colour = actor(color)` – Stewart Ross Mar 11 '18 at 08:15
  • @StewartRoss, that's not necessarily an error so much as redundancy. Try `ggplot(mtcars, aes(mpg,disp)) + geom_point(aes(color=mtcars$cyl))` – r2evans Mar 11 '18 at 11:40

1 Answers1

1

Without the data, it is had to know exactly what is wrong. But here is an example of setting a custom colour scale for points over a violin plot.

ggplot(mtcars, aes(factor(cyl), mpg)) +
  geom_violin() + 
  geom_jitter(height = 0, width = 0.1, aes(colour = factor(gear))) +
  scale_colour_manual(name="colour", values=c("pink", "purple", "orange"))

enter image description here

Michael Harper
  • 14,721
  • 2
  • 60
  • 84