我正在使用ggplot2。我的传奇和轴标题中有物种名称。我发现了一种使整个组变为斜体的方法:主题(legend.position =“right”,axis.text.y = element_text(face =“italic”))但我需要知道如何挑选和选择哪些单词用于斜体。例如,轴标题需要是 Carollia 物种和图例标题 Piper 物种。有什么建议吗?
> head(pie2)
bat piper prop
1 C. castanea P. scintillans 0.51215992
2 C. perspicillata P. scintillans 0.47720417
3 C. sowelli P. scintillans 0.61759343
4 C. castanea P. reticulatum 0.08928571
5 C. perspicillata P. reticulatum 0.04177665
6 C. sowelli P. reticulatum 0.02287988
pie2 %>%
mutate(piper = factor(piper, levels = unique(pie2$piper))) %>%
ggplot(aes(x=bat, y=prop, fill = piper)) +
geom_bar(stat = 'identity', position = 'stack') +
theme_minimal() +
theme(legend.position="bottom")+
scale_fill_brewer(palette=3, direction = -1)+
coord_flip()+
labs(y='Proportion in Diet', x='Carollia Species')+
guides(fill=guide_legend(title="Piper Species"))+
theme(legend.position="right", axis.text.y = element_text(face = "italic"))