Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default label font type to italic in radarchart ("fmsb" package)?

I have created a radar chart for showing the variation of Cultural Indexes (CI) of a number of species with respect to the location. However, since species names must be written in italic or underlined, I need to change the default font type used for the label items. I have been searching internet for many days how to do it without succes. It seems that the question has been asked before but no substantial answers. I would appreciate any help please. Here is the my data and this is the code:

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() output:

radarchart() output

like image 951
Médard Kafoutchoni Avatar asked Oct 29 '25 18:10

Médard Kafoutchoni


1 Answers

I finally found the solution. All we need is to set the family and font plotting parameters to the values we want before calling radarchart(). This can be done via par().

Setting the default font family

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

Plotting the radarchart

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

reset plotting parameters

par(op)

The above code produces: Image

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

like image 114
Médard Kafoutchoni Avatar answered Nov 01 '25 07:11

Médard Kafoutchoni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!