GGPLOT仅更改图例中某些部分的字体
是否可以将鱼的科学名称透露在X轴上和传说中,并在其余部分中使用正常字体?
就我而言,我希望这样做,例如barbatula barbatula(bachschmerle),只有barbatula barbatula在正常字体
我的代码是:
ggplot(R_Sandbach, aes(x = fct_infreq (Species), fill=Species ))+
geom_bar()+
theme_minimal()+
geom_text(aes(label=..count..), stat = "count", vjust = -.1, colour= "black")+
theme(axis.text.x = element_text(angle = 90, size = 5))+
xlab("Fischarten")+
ylab("Individuenanzahl")
Is it possible to put the scientific names of the fish in italics on the x-axis and in the legend and to use normal font for the rest?
In my case I would like that for example Barbatula barbatula (Bachschmerle) only Barbatula barbatula is in italics and (Bachscmerle) in the normal font
This is the bar chart right now
And this is a part of the data im using
My code is:
ggplot(R_Sandbach, aes(x = fct_infreq (Species), fill=Species ))+
geom_bar()+
theme_minimal()+
geom_text(aes(label=..count..), stat = "count", vjust = -.1, colour= "black")+
theme(axis.text.x = element_text(angle = 90, size = 5))+
xlab("Fischarten")+
ylab("Individuenanzahl")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ggtext
绝对是一个不错的选择,尽管您可以像您在问题中所做的那样直接使用主题
直接操纵图的各个方面。请参阅下面的示例:
这将产生一个带有斜面标题和X轴的空白图。您可以根据需要将尽可能多的更改添加到
them>
函数中。编辑:
如果您需要斜体字标题的特定单词等。
根据我的个人经验,这有时会引起GGPLOT的一般主题的问题。
使用此软件包
库(MDTHEMES)
解决了HTML的问题未被读取。例如:
ggtext
is definitely a good option, although you can just manipulate aspects of your plot directly usingtheme
as you've done in your question.See an example below:
This produces a blank plot with the plot title and x axis both in italics. You can add as many changes into your
theme()
function as you like.EDIT:
In the case of which you need specific words of your titles in italics, etc. you can manually incorporate html into your text and then format your plot to read this html.
In my personal experience this has sometimes caused issues with the general themes of ggplot.
Using this package
library(mdthemes)
solves the issues of html not being read as it should.For example: