Skip to content

Points don't inherit font family #4305

Closed as not planned
Closed as not planned
@botanize

Description

@botanize

I expect that the font-family specified in the theme is applied to all applicable graphical content. However, when specifying some unicode characters for the shape scale I get empty boxes instead of the characters. Point geometries can use arbitrary characters for the shape scale, but not all characters are available in all font families. While constructing the points grob, GeomPoint omits the fontfamily gpar parameter, which means that there is no way to specify a font family that contains the desired characters. The standard ways of specifying a font family for the quartz device don't work for the gpar fontfamily (quartz(family =, or quartzFonts(sans = quartzFont(…).

library(ggplot2)
library(grid)

theme_set(theme_minimal(base_family = 'Apple SD Gothic Neo'))

p = ggplot(data.frame(x = 1:3, y = 1:3, shape = factor(0:2)), aes(x, y)) + geom_point(aes(shape = shape), size = 4) + scale_shape_manual(values = c('0' = '\u2013', '1' = '', '2' = '\u25B6')) + theme(text = element_text(family = 'Apple SD Gothic Neo'))
print(p)
data = ggplot_build(p)
gtable = ggplot_gtable(data)
grid.draw(gtable)

# add family to gpar for points grob
gtable$grobs[[6]]$children[[3]]$gp$fontfamily = 'Apple SD Gothic Neo'
grid.newpage()
grid.draw(gtable)

Created on 2020-12-29 by the reprex package (v0.3.0)

I get the behavior I want by adding the font family gpar parameter to the correct grobs as above or to the gtable itself:

data = ggplot_build(p)
gtable = ggplot_gtable(data)
gtable$gp = gpar(fontfamily = 'Apple SD Gothic Neo')
grid.draw(gtable)

From a user perspective, I think this could be fixed by either adding a family parameter to scale_shape or inheriting the family from the theme or device.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions