3

我创建了一个雷达图,用于显示一些物种相对于位置的文化指数 (CI) 的变化。但是,由于物种名称必须用斜体或下划线书写,我需要更改用于标签项的默认字体类型。我已经在互联网上搜索了很多天,但没有成功。似乎这个问题已经被问过,但没有实质性的答案。我会很感激任何帮助。这是我的数据,这是代码:

library(fmsb)
colors_border=c( rgb(0.2,0.5,0.5,0.9), rgb(0.8,0.2,0.5,0.9) , rgb(0.7,0.5,0.1,0.9))
colors_in=c(rgb(0.2,0.5,0.5,0.3), rgb(0.8,0.2,0.5,0.3) , rgb(0.7,0.5,0.1,0.3))
radarchart( data  , axistype=1 , pcol=colors_border, pfcol=colors_in, plwd=2.5, plty=1, cglcol="grey", cglty=1, axislabcol="grey40", caxislabels=seq(0,1,0.25), cglwd=0.8, calcex = 0.8, vlabels = c("A. pubescens", "A. alboviolaceum", "A. angustifolium", "A. melegueta", "C. anisata", "C. giganteus", "L. chevalieri", "M. myristica", "P. guineense", "S. longipedunculata",  "T. sanguinea", "U. chamae", "X. aethiopica", "Z. zanthoxyloides"), vlcex=0.8)
legend(x=1.3, y=1.2, legend = rownames(data[-c(1,2),]), bty = "n", pch=20, col=colors_border, text.col = "grey25", cex=0.8, pt.cex=1.5)

radarchart()输出:

雷达图()输出

4

1 回答 1

4

我终于找到了解决方案。我们只需要在调用之前将系列和字体绘图参数设置为我们想要的值radarchart()。这可以通过par().

设置默认字体系列

op <- par(family = "Times New Roman", font=3)
colors_border=c( rgb(0.2,0.5,0.5,0.9), rgb(0.8,0.2,0.5,0.9), rgb(0.7,0.5,0.1,0.9))
colors_in=c(rgb(0.2,0.5,0.5,0.3), rgb(0.8,0.2,0.5,0.3),
rgb(0.7,0.5,0.1,0.3))

绘制雷达图

radarchart( data  , axistype=1,pcol=colors_border, pfcol=colors_in,
plwd=2.5, plty=1, cglcol="grey", cglty=1, axislabcol="grey40",
caxislabels=seq(0,1,0.25), cglwd=0.8, calcex = 0.8, vlcex=0.8, vlabels = c("A. pubescens", "A. alboviolaceum", "A. angustifolium", "A. melegueta", "C. anisata", "C. giganteus", "L. chevalieri", "M. tenuifolia", "P. guineense", "S. lonipedunculata", "T. sanguinea", "U. chamae", "X. aethiopica", "Z. zanthoxyloides"))

重置绘图参数

par(op)

上面的代码产生: 图像

资料来源:如何在 R 图中更改图例中的字体系列?

于 2017-10-06T10:40:43.633 回答