0

I want to color the tiles in a geom_tile plot for the combinations for which the chi-square hypothesis is accepted as grey. Add color gradient based on chi-square value for the combinations for which the hypothesis is rejected. Now, the logical values for accepted or rejected is stored in a variable called AR. X3 is the variable used to create color gradient.

What I have tried?

I could only add two different colors if accepted or rejected.

G1<-ggplot(df, aes(x = X1, y = X2)) +
  geom_tile(aes(fill = AR), colour="black") + 
  geom_text(aes(fill = AR, label = ifelse(AR==1,X3,'')))+
  xlab("V1")+
  ylab("V2")+
  scale_fill_manual(values = c("grey", "green"))
show(G1)

A dummy dataset:

X1  X2  AR  X3
A   SUV Yes 12
A   SUV No  22
B   SUV No  8
B   SUV Yes 50
C   car Yes 27
C   SUV No  99
D   SUV Yes 33
D   van Yes 13
E   car No  65
vp_050
  • 583
  • 2
  • 4
  • 16
  • 1
    Can you include some dummy data with the same structure and/or include an example plot so we can test and/or see what is going wrong? – teunbrand Mar 31 '21 at 21:00
  • 1
    You may use the `na.value` trick, as described e.g. here: [Assign specific color to definite value in bar plot using scale_fill_gradientn](https://stackoverflow.com/questions/58698075/assign-specific-color-to-definite-value-in-bar-plot-using-scale-fill-gradientn). In your case it would be something like `ggplot(d, aes(x, y, fill = ifelse(AR == 0, chival, NA))) + geom_tile()`. @teunbrand, just refered to your nice answer! – Henrik Mar 31 '21 at 21:01
  • Also point of pedantry: you never accept a null hypothesis, you only ever fail to reject a null hypothesis – teunbrand Mar 31 '21 at 21:01

0 Answers0