0

I am encountering a problem using viridis with ggplot2 and ggmarginal.

I would like to colorize dots on a Bland-Altman Plot that I am plotting with ggplot2:

diff <- (a1$A1_phones - a1$A1_video)
diffp <- (a1$A1_phones - a1$A1_video)/a1$A1_video*100
sd.diff <- sd(diff)
sd.diffp <- sd(diffp)
my.data <- data.frame(a1$A1_video, a1$A1_phones, diff, diffp)

dev.off()

diffplot <- ggplot(my.data, aes(a1$A1_video, diff)) + 
geom_point(size=2, colour = rgb(0,0,0, alpha = 0.5)) + 
theme_bw() + 
#when the +/- 2SD lines will fall outside the default plot limits 
#Thanks to commenter for noticing this.
ylim(mean(my.data$diff) - 7*sd.diff, mean(my.data$diff) + 7*sd.diff) +
geom_hline(yintercept = 0, linetype = 3) +
geom_hline(yintercept = mean(my.data$diff)) +
geom_hline(yintercept = mean(my.data$diff) + 2*sd.diff, linetype = 2) +
geom_hline(yintercept = mean(my.data$diff) - 2*sd.diff, linetype = 2) +
ylab("Difference Video vs Algorithm [ms]") +
xlab("Average of Video vs Algorithm [ms]")

p<-ggMarginal(diffplot, type="histogram", bins = 40)+ scale_colour_viridis_d()

enter image description here

It would now be very beautiful to colorize the dots from A1_video differently than those from A1_phones and have viridis drawing a continuous density plot.

olibiaz
  • 2,551
  • 4
  • 29
  • 31
Claudio
  • 87
  • 6
  • 1
    Please strip down the parts of your question that are unnecessary. If your question is only about getting the points colored then remove the ggmarginal thing... And please provide some example data. – jkd Jun 19 '19 at 12:53
  • Read and include features from [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269), especially the part about reproducing and pasting your data. The dataset is not available for us to demonstrate with; think of using a smaller example that can be included in your question. – wibeasley Jun 19 '19 at 13:45

1 Answers1

0

I am not sure if this is what you want, please try to be more specific and provide sample data. If you just want the color to change based on another column in the source dataset , it must be specified inside the aes() function:

diffplot <- ggplot(my.data,aes(col=a1$A1_video))