Vega-lite: Easier control over chart font size

Created on 24 Nov 2016  路  8Comments  路  Source: vega/vega-lite

I encountered this issue in Altair:

  • I wish to make a big chart, say 800x600, for a presentation slide
  • The font sizes do not scale with the chart and are too small for my needs
  • I have to change the font size for the axis, legend, and facet, labels and titles each, a total of six places. Figuring out how to do this took a while, and it's quite a bit of code.

In R's ggplot2 you would do this to scale the fonts to size 18 - I think the default is 12.

ggplot(...) + theme_bw(base_size=18)

All the fonts are scaled relative to the base size - some are larger and some are smaller. From a usability perspective this is a really nice feature to have when making plots that are designed to be shared or published in some way.

Most helpful comment

Since vega/vega-parser#18 is closed and doesn't solve the issue,
here are the properties that I had to change to enlarge a graph :

spec.width = 800;
spec.height = 500;
spec.config.axisY.titleFontSize = 14;
spec.config.axisX.titleFontSize = 14;
spec.config.axisY.labelFontSize = 16;
spec.config.axisX.labelFontSize = 16;
spec.title.fontSize = 20;
spec.encoding.color.legend.titleFontSize = 15;
spec.encoding.color.legend.labelFontSize = 15;

(spec is the whole json object)

All 8 comments

Thanks. baseFontSize might be a good name for this, but we need to sync with latest config/theme in Vega and probably make it consistent. #1638

In Vega one would use signal to achieve this kind of effect, as the issue can concern any type of marks. In a higher level grammar this would probably be less intuitive, so what would be the typical vega-lite way?

Since vega/vega-parser#18 is closed and doesn't solve the issue,
here are the properties that I had to change to enlarge a graph :

spec.width = 800;
spec.height = 500;
spec.config.axisY.titleFontSize = 14;
spec.config.axisX.titleFontSize = 14;
spec.config.axisY.labelFontSize = 16;
spec.config.axisX.labelFontSize = 16;
spec.title.fontSize = 20;
spec.encoding.color.legend.titleFontSize = 15;
spec.encoding.color.legend.labelFontSize = 15;

(spec is the whole json object)

Maybe the issue could be reopened then?

If you want to make all fonts larger, you could also make the chart smaller and scale it up. Does that solve the original issue?

@domoritz yes it would solve it, but I only found so far the scaling option for saving charts (I'm using Altair: Figure Size/Resolution doc). I also see a scaleFactor in vega-embed, but it seems also for PNG/SVG rendering only.

For Altair, this wouldn鈥檛 work as easily but if you want to embed a chart in a presentation, you can embed the graphic and resize it.

I agree that it would be nice to have a single place to change the font size. We would need to do it in Vega, though. Could you file an issue there?

Was this page helpful?
0 / 5 - 0 ratings