ggplot(unique(films2[,c("film","word.len.avg")]) ,aes(film,word.len.avg,fill=film,))+
geom_bar_pattern(stat="identity",
pattern =
c(
"circle",
"stripe",
"none",
"wave",
"crosshatch"
),
pattern_angle = c(rep(45, ),
rep(60, ),
rep(45, ),
rep(45, ),
rep(45,)),
fill = 'white',
colour = 'black',
pattern_density = .35,
pattern_fill = 'darkblue',
pattern_colour = 'darkblue'
) +
scale_x_discrete(breaks = c("dial.m.for.murder", "pscyho", "rear.window", "rope", "vertigo"),
labels = c("Dial M for Murder", "Psycho", "Rear Window", "Rope", "Vertigo"))+
theme_bw() +
aes(pattern = film)+
theme(legend.position = "right") +
coord_fixed(ratio = 1.5)+
scale_pattern_spacing_discrete(range = c(0.01, 0.05))
Hi I have the above code for a bar graph with pattern fills. See associated image below. This is code I cobbled together from various sources on stack overflow, and I'm pleased it finally works in that I now finally have five bars with a different fill pattern in each. However, it's clear that these patterns are not necessarily associated with a specific film (there are five values for film). I'm wondering how I can get the pattern fills to be mapped to specific films, because at the moment the legend won't show, and I'm assuming it's because of this (i.e. things haven't been mapped properly?). Any advice would be greatly appreciated. Maro
只是想补充一点,我在网上找到了这个https://evamaerey.github.io/flipbooks/ggpattern/ggpattern#28,它做了我想做的事情,但看起来不像上面的那个那么好.现在就可以了,但是如果有人对如何将两者结合起来,或者如何修改上面的代码,以便我能得到显示的密钥有任何建议,我也将不胜感激!非常感谢.