Search code examples
rdesign-patternsplotggplot2slash

How do I change the pattern with a certain condition in plot R


> VAR     Estimate        ymax        ymin           t.value      SIDE
> TM1     0.45207287  0.55211315    0.3520326      4.5189087      EAST
> TM400   0.24634616  0.294695776   0.19799654     5.0951003      EAST
> TM800   0.22187081  0.270010311   0.17373131     4.6089138      EAST
> TM1    0.03150572   0.115834177  -0.05282274     0.3736072      WEST
> TM400  -0.04242677  -0.006421522  -0.07843202   -1.1783496      WEST
> TM800   0.06834191  0.097380534   0.03930329     2.3534835      WEST

I have above dataset and I made this plot using ggplot2

enter image description here

I would like to adjust the graph this instruction: if t.value < 3, the bar graph is not solid and slash(//) types to fill the graph. Under the same color, I just want to change the pattern solid to hash(////).

How do I add the code? This is my original code.

ggplot(FOR_PLOT_SALE, aes(x=factor(VAR), y=Estimate)) +    
scale_fill_grey() +  facet_grid(. ~ SIDE) +    
geom_bar(stat="identity",aes(fill=VAR)) +     
geom_errorbar(aes(ymin=ymin, ymax= ymax),
                width=.2, 
                position="identity")+   geom_hline(yintercept=0)+   theme_classic()

Solution

  • Unfortunately you did not provide a usable data.frame as an example.

    What about if you try out the following to change the alpha-value of your fill:

    geom_bar(stat = "identity", alpha = ifelse(temp$Max_WS > 10, 1, 0.3))
    

    Or the fill colour itself:

    geom_bar(stat = "identity", fill = ifelse(temp$Max_WS > 10, "black", "grey"))
    

    My preference for your plot would be to not use "fill = VAR" (because it's not necessary), but use the grey shading to visualise "is significant/or is not".