I make d3 plots with r2d3 library in R and try to change the font. Unfortunately it is always Arial that renders at the end. Is there any proven way to make it work?
I have tried this in css file connected to js file:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
text {
font-family: "Fira Sans", sans-serif;
fill: #371ea3;
color: #371ea3;
}
Adding !important does not help.
Font-family changes to "Fira Sans" properly, but in Computed section i can see that rendered font is Arial.
You can use a css file with:
As noted in the documentation here. I took your css and placed it in a file without issue for text drawn within an svg.
With that I successful with the following (adapting the basic example from the documentation):
chart.r:
styles.css:
and chart.js:
Giving:
I also had success with a reduced css file specifying only the font:
And then using
selection.style/attrto style the text:And here's what that approach looked like (again adapting the basic example from the docs)
chart.r:
styles.css:
And chart.js (based on the basic introductory example on the api docs):
Yielding (alternating between default font and Fira Sans for contrast):