如何在雷达图中将默认标签字体类型更改为斜体(" fmsb"包)?

时间:2017-02-03 17:19:03

标签: r fonts label radar-chart italic

我创建了一张雷达图表,显示了许多物种的文化指数(CI)相对于该地点的变化。但是,由于物种名称必须用斜体或下划线表示,我需要更改用于标签项目的默认字体类型。我一直在互联网上搜索如何做到这一点没有成功。似乎question has been asked before但没有实质性答案。我很感激任何帮助。 这是我的data,这是代码:

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()输出:

radarchart() output

1 个答案:

答案 0 :(得分:0)

我终于找到了解决方案。我们所需要的只是在调用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(数据,axistype = 1,pcol = colors_border,pfcol = colors_in,   plwd = 2.5,plty = 1,cglcol =“gray”,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“))

     

重置绘图参数

     

参数(OP)

以上代码产生: Image

来源:How to change font family in a legend in an R-plot?