0

我正在使用ggplot2。我的图例和轴标题中有物种名称。我找到了一种将整个组斜体的方法:theme(legend.position="right", axis.text.y = element_text(face = "italic")) 但我需要知道如何挑选哪些单词要斜体. 例如,轴标题需要为Carollia Species,图例标题为Piper Species。有什么建议么?

> 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"))

图形

4

0 回答 0