trevorld / ggpattern

ggplot geoms with pattern fills
https://trevorldavis.com/R/ggpattern/dev/
Other
359 stars 18 forks source link

The legend is a little different from the main plot #28

Closed zhanghaoipp closed 3 years ago

zhanghaoipp commented 3 years ago

I use the command bleow to make the bar plot, but you can see the patten spacing in the legend and main plot is different, the legend is smaller. How to resolve this problem? Thank you!

ggplot(tg, aes(x=Sample.x, y=content)) + geom_col_pattern(aes(pattern=toxin), pattern_spacing=0.01, pattern_fill='black', pattern_color='black', fill='white', color='black') + geom_errorbar(aes(ymin = error_min, ymax=error_max), width=0.4) + theme(panel.background = element_blank(), axis.line = element_line(colour = 'black'), legend.title = element_blank()) + xlab('') + ylab('mg/kg') + geom_text(x='287', y=0.09, label='') + geom_text(x='272', y=0.17, label='') + geom_hline(yintercept = mean(grain$sum), linetype = 'dashed', color='grey50') Figure6-3

trevorld commented 3 years ago

The aesthetic pattern_key_scale_factor can be used to adjust the legend pattern spacing.