Texture in barplot using ggplot

I did as mentioned in this stackoverflow.
But, in my case, all the bar has the same height.

Could anyone check what went wrong with mine?

Here is the code

thank you

mat_d11=data.frame(
  month=month.name[rep(c(1:12), each = 4)],
  V1=round(runif(48,0,1),2),  
  var=rep(c("a","b","c","d"),12)
)
mat_d11$var=as.factor(mat_d11$var)
  
ggplot(data = mat_d11, aes(x = factor(month), fill = V1, pattern = var)) +
  geom_bar_pattern(position = "Dodge",
                   color = "black", 
                   pattern_fill = "black",
                   pattern_angle = 0,
                   pattern_density = 0.1,
                   pattern_spacing = 0.05,
                   pattern_key_scale_factor = 0.6) 

Found the solution, if anyone is interested, here it is

library(ggplot2)
library(ggpattern)
mat_d11=data.frame(
  month=month.name[rep(c(1:12), each = 4)],
  V1=round(runif(48,0,1),2),  
  var=rep(c("a","b","c","d"),12)
)
mat_d11$var=as.factor(mat_d11$var)

ggplot(mat_d11, aes(x = month, y = V1, fill = var)) +
  geom_col_pattern(
    aes(pattern = var),
    colour = "black",
    pattern_fill = "black",
    pattern_angle = 45,
    pattern_density = 0.1,
    pattern_spacing = 0.01,
    position = position_dodge2(preserve = 'single'),
  ) 

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.