Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct fonts in labels #67

Merged
merged 57 commits into from
Nov 17, 2020
Merged

Correct fonts in labels #67

merged 57 commits into from
Nov 17, 2020

Conversation

dlcomeaux
Copy link
Collaborator

Use finalize_plot() to update font faces, families, sizes, and colors for text added to the plot through geom_text() or annotate(). Requires hard-coded alternative to default value because font sizes are not playing nice.

Use finalize_plot() to update font faces, families, sizes, and colors for text added to the plot through geom_text() or annotate(). Requires hard-coded alternative to default value because font sizes are not playing nice.
@matthewstern
Copy link
Contributor

I'm OK with this change although (I know I sound like a broken record but...) I don't love that it kicks in at finalize and not at theme_cmap. I can't think of a clean or effective way to put it in theme, though.

We should specify in documentation, I think, that font can be set by specifying aesthetics in geom_text() if the user wants to. Which brings back up the question of user access to variables in cmapplot_globals.

Instead of main, for on-chart labels.
Makes the hard-coding more obvious. Also, I added a light gray color.
@dlcomeaux dlcomeaux added the bug Something isn't working label Oct 23, 2020
@dlcomeaux
Copy link
Collaborator Author

@matthewstern I agree that doing this in finalize is not ideal. This may be an issue of having an incomplete theme, although I'm not sure about that. That's my best guess, though.

To your question - after I use load_all() I am able to access things in the cmapplot_globals stack, so I think that they are user-callable. Unless there are things there that are usable with load_all but not if you install the package? I'm not sure how that works.

@nmpeterson
Copy link
Contributor

cmapplot_globals is NOT available when cmapplot is loaded via library(cmapplot).

@dlcomeaux
Copy link
Collaborator Author

dlcomeaux commented Oct 26, 2020 via email

@matthewstern
Copy link
Contributor

Following up on the discussion here, it looks like the authors of ggplot recommend explicitly building off a built-in ggplot theme if creating a custom theme. This should enable our theme to be 'complete'. Perhaps this in combination with an understanding of the base theme arguments might help us solve our font size issue. A man can dream...

I can try to look into this in the coming days if no one else gets to it first.

R/finalize_plot.R Outdated Show resolved Hide resolved
R/cmapplot.R Outdated Show resolved Hide resolved
@dlcomeaux dlcomeaux marked this pull request as draft November 2, 2020 19:17
@dlcomeaux
Copy link
Collaborator Author

Changing to draft because we will need to give this some more thought after #72 is merged.

@dlcomeaux
Copy link
Collaborator Author

I updated this to accommodate the new theme_cmap conventions. Unfortunately, the font sizes still don't correspond to what we would want them to - you need to input a size of 5 for it to output at size 14, which I've done by multiplying M by 5/14. This is certainly not ideal, and I'm open to other ideas on what might be causing the problem. For now, though, this works.

@nmpeterson
Copy link
Contributor

If the labels are supposed to use Whitney Semibold (which you had in your previous iteration), then they should now use the strong font spec instead of regular.

@dlcomeaux
Copy link
Collaborator Author

Oops, good catch, yes @nmpeterson

from regular to strong
@matthewstern
Copy link
Contributor

matthewstern commented Nov 2, 2020

I presume you've seen this but it looks like you're not the only one who has decided 14/5 is the right ratio.

https://stackoverflow.com/questions/25061822/ggplot-geom-text-font-size-control/25062509

"it's the difference in units, geom_text default of 5 might be 5mm and the theme() size unit is point. 1 point is 1/72 inch=0.35mm, so 1 in geom_text() is 1mm, 1/0.35 =~ 14/5"

The unit of size strikes again!

@nmpeterson
Copy link
Contributor

@dlcomeaux @matthewstern I just discovered that ggplot2::.pt (=2.845276, slightly greater than 14/5) is used internally by ggplot2 to convert mm to pt and vice versa. Help description for .pt and .stroke: "Multiply size in mm by these constants in order to convert to the units that grid uses internally for lwd and fontsize."

@matthewstern
Copy link
Contributor

@dlcomeaux @matthewstern I just discovered that ggplot2::.pt (=2.845276, slightly greater than 14/5) is used internally by ggplot2 to convert mm to pt and vice versa. Help description for .pt and .stroke: "Multiply size in mm by these constants in order to convert to the units that grid uses internally for lwd and fontsize."

This suggests that we may want to revisit our size conversion function. It may become irrelevant if we can directly convert sizes to mm and then multiply explicitly by ggplot's built-in constant. The help file isn't clear... I presume .stroke is for lwd and .pt is for font size? Interesting that they are different from one another.

@nmpeterson
Copy link
Contributor

That was the impression I got, too, but yes -- unclear.

@dlcomeaux
Copy link
Collaborator Author

OK @matthewstern @nmpeterson I'll give it a try and see if I can make a new version of the function work.

@matthewstern matthewstern marked this pull request as ready for review November 17, 2020 07:05
@matthewstern
Copy link
Contributor

matthewstern commented Nov 17, 2020

I believe this is ready for review. In addition to incorporating the changes from #81, this PR also:

  • addresses sizing concerns by establishing a new constant .lwd and updating the function now called gg_lwd_convert.
  • corrected the topline width drawn by finalize
  • renames the constant lwd_originline to lwd_strongline as its use is not restricted to origins
  • many improvements to the plots.Rmd vignette, including incorporating a new section on the new apply_cmap_default_aes
  • added new fns to pkgdown.yml.

This was linked to issues Nov 17, 2020
vignettes/plots.Rmd Outdated Show resolved Hide resolved
nmpeterson and others added 3 commits November 17, 2020 12:18
Looks good. Should double check with Comms.
and update documentation accordingly
@matthewstern matthewstern linked an issue Nov 17, 2020 that may be closed by this pull request
dlcomeaux and others added 8 commits November 17, 2020 14:01
Replaces two calls in the build_chart function with calls that allow for finalizing non-cmap themed charts.

@matthewstern I used `theme_get` instead of `ggplot_globals` to remove the call to an unexported element, since check() was throwing some exceptions to that.
package will error on load if the list produced by `init_cmap_default_aes` does not line up with `cmapplot_globals$geoms_that_change`
Also explicitly call dplyr when using `first`
to 0.9.2 from 0.9.1
R/theme_cmap.R Outdated Show resolved Hide resolved
@matthewstern matthewstern merged commit 4267bad into master Nov 17, 2020
@matthewstern matthewstern deleted the label_fonts branch November 17, 2020 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

error in finalize w/o theme_cmap Improving default panel spacing Improvements based on comms review
3 participants