Is there any possibility of using imported fonts with r2d3?Arial specified in CSS breaks site in IE9What system fonts are available to PIL on Google App Engine?How to import an SQL file using the command line in MySQL?Ipad/iPhone fonts not rendering properlyFonts changing weight when uploaded to web serverHow to use Open Sans font with cakePhp 3?WebFont @font-face define serif/sans-serif/monospaceThe browser is using sans-serif even though Arial is availableStrange (Wrong?) font selection in agency.css?Fira Sans font face not picking in firefox
In the Marvel universe, can a human have a baby with any non-human?
Why is C++ initial allocation so much larger than C's?
How come I was asked by a CBP officer why I was in the US?
Are there any vegetarian astronauts?
What are the benefits of using the X Card safety tool in comparison to plain communication?
Can a Horncaller control a Druid who is using Wild Shape?
Going to get married soon, should I do it on Dec 31 or Jan 1?
Fedora boot screen shows both Fedora logo and Lenovo logo. Why and How?
How to reply to small talk/random facts in a non-offensive way?
Unusual mail headers, evidence of an attempted attack. Have I been pwned?
Why does the numerical solution of an ODE move away from an unstable equilibrium?
Does the posterior necessarily follow the same conditional dependence structure as the prior?
Should I include salary information on my CV?
Should my manager be aware of private LinkedIn approaches I receive? How to politely have this happen?
Can ADFS connect to other SSO services?
Short and long term plans in a closed game in the Sicilian Defense
How to determine what is the correct level of detail when modelling?
Story-based adventure with functions and relationships
What reason would an alien civilization have for building a Dyson Sphere (or Swarm) if cheap Nuclear fusion is available?
When is it ok to add filler to a story?
Do French speakers not use the subjunctive informally?
Would a two-seat light aircaft with a landing speed of 20 knots and a top speed of 180 knots be technically possible?
How to split an equation over two lines?
Abel-Jacobi map on symmetric product of genus 4 curve
Is there any possibility of using imported fonts with r2d3?
Arial specified in CSS breaks site in IE9What system fonts are available to PIL on Google App Engine?How to import an SQL file using the command line in MySQL?Ipad/iPhone fonts not rendering properlyFonts changing weight when uploaded to web serverHow to use Open Sans font with cakePhp 3?WebFont @font-face define serif/sans-serif/monospaceThe browser is using sans-serif even though Arial is availableStrange (Wrong?) font selection in agency.css?Fira Sans font face not picking in firefox
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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.
r d3.js import fonts r2d3
add a comment |
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.
r d3.js import fonts r2d3
add a comment |
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.
r d3.js import fonts r2d3
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.
r d3.js import fonts r2d3
r d3.js import fonts r2d3
asked Mar 25 at 10:26
FeatenFeaten
61 bronze badge
61 bronze badge
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use a css file with:
r2d3(data, script = "script.js", css = "styles.css")
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:
library(r2d3)
data <- c(0.3, 0.6, 0.8, 0.95, 0.40, 0.20)
r2d3(data, script = "chart.js", css="styles.css")
styles.css:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
text
font-family: "Fira Sans", sans-serif;
fill: #371ea3; /* no need for 'color' */
and chart.js:
var barHeight = Math.floor(height / data.length);
svg.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('width', function(d) return d * width; )
.attr('height', barHeight)
.attr('y', function(d, i) return i * barHeight; )
.attr('fill', 'steelblue');
svg.selectAll('text')
.data(data)
.enter()
.append('text')
.attr('x',20)
.attr('y', function(d,i) return i * barHeight + 30)
.text(function(d) return d; )
Giving:
I also had success with a reduced css file specifying only the font:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
And then using selection.style/attr
to style the text:
selection.attr('font-family', "FontFamilyName"); // or:
selection.style('font-family', "FontFamiliyName");
And here's what that approach looked like (again adapting the basic example from the docs)
chart.r:
library(r2d3)
data <- c(0.3, 0.6, 0.8, 0.95, 0.40, 0.20)
r2d3(data, script = "chart.js", css="styles.css")
styles.css:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
And chart.js (based on the basic introductory example on the api docs):
var barHeight = Math.floor(height / data.length);
svg.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('width', function(d) return d * width; )
.attr('height', barHeight)
.attr('y', function(d, i) return i * barHeight; )
.attr('fill', 'steelblue');
svg.selectAll('text')
.data(data)
.enter()
.append('text')
.attr('x',20)
.attr('y', function(d,i) return i * barHeight + 10)
.text(function(d) return d; )
.style('font-family',function(d,i)
if(i%2 == 1) return 'Fira Sans'; else return ''; // for contrast.
);
Yielding (alternating between default font and Fira Sans for contrast):
I did exactly the same thing just now and my plot looks like this: imgur.com/a/CoPMwwa
– Featen
Mar 27 at 8:48
@Featen, Hmm, I tried the second option again, copying the code from the answer, on a different system, running RStudio (v1.0.136 (2016)), and still works for me. Seems I'm out of ideas, sorry that I can't be of much more of a help.
– Andrew Reid
Mar 28 at 2:11
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55335701%2fis-there-any-possibility-of-using-imported-fonts-with-r2d3%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use a css file with:
r2d3(data, script = "script.js", css = "styles.css")
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:
library(r2d3)
data <- c(0.3, 0.6, 0.8, 0.95, 0.40, 0.20)
r2d3(data, script = "chart.js", css="styles.css")
styles.css:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
text
font-family: "Fira Sans", sans-serif;
fill: #371ea3; /* no need for 'color' */
and chart.js:
var barHeight = Math.floor(height / data.length);
svg.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('width', function(d) return d * width; )
.attr('height', barHeight)
.attr('y', function(d, i) return i * barHeight; )
.attr('fill', 'steelblue');
svg.selectAll('text')
.data(data)
.enter()
.append('text')
.attr('x',20)
.attr('y', function(d,i) return i * barHeight + 30)
.text(function(d) return d; )
Giving:
I also had success with a reduced css file specifying only the font:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
And then using selection.style/attr
to style the text:
selection.attr('font-family', "FontFamilyName"); // or:
selection.style('font-family', "FontFamiliyName");
And here's what that approach looked like (again adapting the basic example from the docs)
chart.r:
library(r2d3)
data <- c(0.3, 0.6, 0.8, 0.95, 0.40, 0.20)
r2d3(data, script = "chart.js", css="styles.css")
styles.css:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
And chart.js (based on the basic introductory example on the api docs):
var barHeight = Math.floor(height / data.length);
svg.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('width', function(d) return d * width; )
.attr('height', barHeight)
.attr('y', function(d, i) return i * barHeight; )
.attr('fill', 'steelblue');
svg.selectAll('text')
.data(data)
.enter()
.append('text')
.attr('x',20)
.attr('y', function(d,i) return i * barHeight + 10)
.text(function(d) return d; )
.style('font-family',function(d,i)
if(i%2 == 1) return 'Fira Sans'; else return ''; // for contrast.
);
Yielding (alternating between default font and Fira Sans for contrast):
I did exactly the same thing just now and my plot looks like this: imgur.com/a/CoPMwwa
– Featen
Mar 27 at 8:48
@Featen, Hmm, I tried the second option again, copying the code from the answer, on a different system, running RStudio (v1.0.136 (2016)), and still works for me. Seems I'm out of ideas, sorry that I can't be of much more of a help.
– Andrew Reid
Mar 28 at 2:11
add a comment |
You can use a css file with:
r2d3(data, script = "script.js", css = "styles.css")
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:
library(r2d3)
data <- c(0.3, 0.6, 0.8, 0.95, 0.40, 0.20)
r2d3(data, script = "chart.js", css="styles.css")
styles.css:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
text
font-family: "Fira Sans", sans-serif;
fill: #371ea3; /* no need for 'color' */
and chart.js:
var barHeight = Math.floor(height / data.length);
svg.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('width', function(d) return d * width; )
.attr('height', barHeight)
.attr('y', function(d, i) return i * barHeight; )
.attr('fill', 'steelblue');
svg.selectAll('text')
.data(data)
.enter()
.append('text')
.attr('x',20)
.attr('y', function(d,i) return i * barHeight + 30)
.text(function(d) return d; )
Giving:
I also had success with a reduced css file specifying only the font:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
And then using selection.style/attr
to style the text:
selection.attr('font-family', "FontFamilyName"); // or:
selection.style('font-family', "FontFamiliyName");
And here's what that approach looked like (again adapting the basic example from the docs)
chart.r:
library(r2d3)
data <- c(0.3, 0.6, 0.8, 0.95, 0.40, 0.20)
r2d3(data, script = "chart.js", css="styles.css")
styles.css:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
And chart.js (based on the basic introductory example on the api docs):
var barHeight = Math.floor(height / data.length);
svg.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('width', function(d) return d * width; )
.attr('height', barHeight)
.attr('y', function(d, i) return i * barHeight; )
.attr('fill', 'steelblue');
svg.selectAll('text')
.data(data)
.enter()
.append('text')
.attr('x',20)
.attr('y', function(d,i) return i * barHeight + 10)
.text(function(d) return d; )
.style('font-family',function(d,i)
if(i%2 == 1) return 'Fira Sans'; else return ''; // for contrast.
);
Yielding (alternating between default font and Fira Sans for contrast):
I did exactly the same thing just now and my plot looks like this: imgur.com/a/CoPMwwa
– Featen
Mar 27 at 8:48
@Featen, Hmm, I tried the second option again, copying the code from the answer, on a different system, running RStudio (v1.0.136 (2016)), and still works for me. Seems I'm out of ideas, sorry that I can't be of much more of a help.
– Andrew Reid
Mar 28 at 2:11
add a comment |
You can use a css file with:
r2d3(data, script = "script.js", css = "styles.css")
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:
library(r2d3)
data <- c(0.3, 0.6, 0.8, 0.95, 0.40, 0.20)
r2d3(data, script = "chart.js", css="styles.css")
styles.css:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
text
font-family: "Fira Sans", sans-serif;
fill: #371ea3; /* no need for 'color' */
and chart.js:
var barHeight = Math.floor(height / data.length);
svg.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('width', function(d) return d * width; )
.attr('height', barHeight)
.attr('y', function(d, i) return i * barHeight; )
.attr('fill', 'steelblue');
svg.selectAll('text')
.data(data)
.enter()
.append('text')
.attr('x',20)
.attr('y', function(d,i) return i * barHeight + 30)
.text(function(d) return d; )
Giving:
I also had success with a reduced css file specifying only the font:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
And then using selection.style/attr
to style the text:
selection.attr('font-family', "FontFamilyName"); // or:
selection.style('font-family', "FontFamiliyName");
And here's what that approach looked like (again adapting the basic example from the docs)
chart.r:
library(r2d3)
data <- c(0.3, 0.6, 0.8, 0.95, 0.40, 0.20)
r2d3(data, script = "chart.js", css="styles.css")
styles.css:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
And chart.js (based on the basic introductory example on the api docs):
var barHeight = Math.floor(height / data.length);
svg.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('width', function(d) return d * width; )
.attr('height', barHeight)
.attr('y', function(d, i) return i * barHeight; )
.attr('fill', 'steelblue');
svg.selectAll('text')
.data(data)
.enter()
.append('text')
.attr('x',20)
.attr('y', function(d,i) return i * barHeight + 10)
.text(function(d) return d; )
.style('font-family',function(d,i)
if(i%2 == 1) return 'Fira Sans'; else return ''; // for contrast.
);
Yielding (alternating between default font and Fira Sans for contrast):
You can use a css file with:
r2d3(data, script = "script.js", css = "styles.css")
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:
library(r2d3)
data <- c(0.3, 0.6, 0.8, 0.95, 0.40, 0.20)
r2d3(data, script = "chart.js", css="styles.css")
styles.css:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
text
font-family: "Fira Sans", sans-serif;
fill: #371ea3; /* no need for 'color' */
and chart.js:
var barHeight = Math.floor(height / data.length);
svg.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('width', function(d) return d * width; )
.attr('height', barHeight)
.attr('y', function(d, i) return i * barHeight; )
.attr('fill', 'steelblue');
svg.selectAll('text')
.data(data)
.enter()
.append('text')
.attr('x',20)
.attr('y', function(d,i) return i * barHeight + 30)
.text(function(d) return d; )
Giving:
I also had success with a reduced css file specifying only the font:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
And then using selection.style/attr
to style the text:
selection.attr('font-family', "FontFamilyName"); // or:
selection.style('font-family', "FontFamiliyName");
And here's what that approach looked like (again adapting the basic example from the docs)
chart.r:
library(r2d3)
data <- c(0.3, 0.6, 0.8, 0.95, 0.40, 0.20)
r2d3(data, script = "chart.js", css="styles.css")
styles.css:
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600');
And chart.js (based on the basic introductory example on the api docs):
var barHeight = Math.floor(height / data.length);
svg.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('width', function(d) return d * width; )
.attr('height', barHeight)
.attr('y', function(d, i) return i * barHeight; )
.attr('fill', 'steelblue');
svg.selectAll('text')
.data(data)
.enter()
.append('text')
.attr('x',20)
.attr('y', function(d,i) return i * barHeight + 10)
.text(function(d) return d; )
.style('font-family',function(d,i)
if(i%2 == 1) return 'Fira Sans'; else return ''; // for contrast.
);
Yielding (alternating between default font and Fira Sans for contrast):
answered Mar 25 at 23:07
Andrew ReidAndrew Reid
20.6k4 gold badges26 silver badges49 bronze badges
20.6k4 gold badges26 silver badges49 bronze badges
I did exactly the same thing just now and my plot looks like this: imgur.com/a/CoPMwwa
– Featen
Mar 27 at 8:48
@Featen, Hmm, I tried the second option again, copying the code from the answer, on a different system, running RStudio (v1.0.136 (2016)), and still works for me. Seems I'm out of ideas, sorry that I can't be of much more of a help.
– Andrew Reid
Mar 28 at 2:11
add a comment |
I did exactly the same thing just now and my plot looks like this: imgur.com/a/CoPMwwa
– Featen
Mar 27 at 8:48
@Featen, Hmm, I tried the second option again, copying the code from the answer, on a different system, running RStudio (v1.0.136 (2016)), and still works for me. Seems I'm out of ideas, sorry that I can't be of much more of a help.
– Andrew Reid
Mar 28 at 2:11
I did exactly the same thing just now and my plot looks like this: imgur.com/a/CoPMwwa
– Featen
Mar 27 at 8:48
I did exactly the same thing just now and my plot looks like this: imgur.com/a/CoPMwwa
– Featen
Mar 27 at 8:48
@Featen, Hmm, I tried the second option again, copying the code from the answer, on a different system, running RStudio (v1.0.136 (2016)), and still works for me. Seems I'm out of ideas, sorry that I can't be of much more of a help.
– Andrew Reid
Mar 28 at 2:11
@Featen, Hmm, I tried the second option again, copying the code from the answer, on a different system, running RStudio (v1.0.136 (2016)), and still works for me. Seems I'm out of ideas, sorry that I can't be of much more of a help.
– Andrew Reid
Mar 28 at 2:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55335701%2fis-there-any-possibility-of-using-imported-fonts-with-r2d3%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown