ggplot(BQG,mapping = aes(x=groupf,y=FD_log,shape=groupf))+ geom_violin(aes(fill=groupf),alpha=0.2)+ scale_fill_manual("", values = c("red","green","blue"))+ geom_jitter(width = 0.25)+ labs(x="分组",y="lg(丰度)")+ theme_gdocs()+ theme_classic()+ guides(fill = guide_legend(title = ""), shape = guide_legend(title = "")) 修改这段代码,让图中字体全变为宋体,且保留theme_classic()的一些参数
时间: 2023-10-31 17:06:21 浏览: 69
可以使用`theme()`函数来修改字体,将`theme_gdocs()`替换为`theme_classic()`,并添加修改字体的参数即可。
修改后的代码如下:
```
ggplot(BQG, mapping = aes(x = groupf, y = FD_log, shape = groupf)) +
geom_violin(aes(fill = groupf), alpha = 0.2) +
scale_fill_manual("", values = c("red", "green", "blue")) +
geom_jitter(width = 0.25) +
labs(x = "分组", y = "lg(丰度)") +
theme_classic() +
theme(
text = element_text(family = "SimSun")
) +
guides(fill = guide_legend(title = ""), shape = guide_legend(title = ""))
```
其中,`SimSun`为宋体的英文名称。如果需要修改其他字体,可以将`SimSun`替换为其他字体的英文名称即可。注意,保留`theme_classic()`的一些参数需要将`theme_gdocs()`替换为`theme_classic()`,不能同时存在。
相关问题
ggplot(BQG,mapping = aes(x=groupf,y=FD_log,shape=groupf))+ geom_violin(aes(fill=groupf),alpha=0.2)+ scale_fill_manual("", values = c("red","green","blue"))+ geom_jitter(width = 0.25)+ labs(x="分组",y="lg(丰度)")+ theme_gdocs()+ theme_classic()+ guides(fill = guide_legend(title = ""), shape = guide_legend(title = "")) 修改这段代码,让图中字体全变为宋体
可以使用`theme()`函数来修改字体,将`theme_gdocs()`和`theme_classic()`替换为`theme()`,并修改字体为宋体即可。
修改后的代码如下:
```
ggplot(BQG, mapping = aes(x = groupf, y = FD_log, shape = groupf)) +
geom_violin(aes(fill = groupf), alpha = 0.2) +
scale_fill_manual("", values = c("red", "green", "blue")) +
geom_jitter(width = 0.25) +
labs(x = "分组", y = "lg(丰度)") +
theme(
text = element_text(family = "SimSun")
) +
guides(fill = guide_legend(title = ""), shape = guide_legend(title = ""))
```
其中,`SimSun`为宋体的英文名称。如果需要修改其他字体,可以将`SimSun`替换为其他字体的英文名称即可。
修改这段代码,让图中出现的文字全变为宋体,ggplot(BQG,mapping = aes(x=groupf,y=FD_log,shape=groupf))+ geom_violin(aes(fill=groupf),alpha=0.2)+ scale_fill_manual("", values = c("red","green","blue"))+ geom_jitter(width = 0.25)+ labs(x="分组",y="lg(丰度)")+ theme_gdocs()+ theme_classic()+ guides(fill = guide_legend(title = ""), shape = guide_legend(title = ""))
ggplot(BQG,mapping = aes(x=groupf,y=FD_log,shape=groupf)) +
geom_violin(aes(fill=groupf),alpha=0.2) +
scale_fill_manual("", values = c("red","green","blue")) +
geom_jitter(width = 0.25) +
labs(x="分组",y="lg(丰度)") +
theme_gdocs(base_family = "SimSun") +
theme_classic(base_family = "SimSun") +
guides(fill = guide_legend(title = ""), shape = guide_legend(title = ""))
将 `theme_gdocs()` 和 `theme_classic()` 函数中的 `base_family` 参数设置为 `"SimSun"` 即可将字体改为宋体。
阅读全文