Git Product home page Git Product logo

hrbrthemes's Introduction

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Signed by Signed commit %

cran checks CRAN status Minimal R Version License downloads DOI

hrbrthemes

Additional Themes and Theme Components for ‘ggplot2’


This is a very focused package that provides typography-centric themes and theme components for ggplot2.

The core theme: theme_ipsum (“ipsum” is Latin for “precise”) uses Arial Narrow which should be installed on practically any modern system, so it’s “free”-ish. This font is condensed, has solid default kerning pairs and geometric numbers. That’s what I consider the “font trifecta” must-have for charts. An additional quality for fonts for charts is that they have a diversity of weights. Arial Narrow (the one on most systems, anyway) does not have said diversity but this quality is not (IMO) a “must have”.

The following functions are implemented/objects are exported:

Themes:

  • theme_ipsum: Arial Narrow
  • theme_ipsum_gs: Goldman Sans Condensed
  • theme_ipsum_es: Econ Sans Condensed
  • theme_ipsum_rc: Roboto Condensed
  • theme_ipsum_ps: IBM Plex Sans font
  • theme_ipsum_pub: Public Sans
  • theme_ipsum_tw: Titilium Web
  • theme_modern_rc: Roboto Condensed dark theme
  • theme_ft_rc: Dark theme based on FT’s dark theme (Roboto Condensed)

Scales (that align with various themes):

  • scale_color_ipsum: Discrete color & fill scales based on the ipsum palette
  • scale_colour_ipsum: Discrete color & fill scales based on the ipsum palette
  • scale_fill_ipsum: Discrete color & fill scales based on the ipsum palette
  • scale_color_ft: Discrete color & fill scales based on the FT palette
  • scale_colour_ft: Discrete color & fill scales based on the FT palette
  • scale_fill_ft: Discrete color & fill scales based on the FT palette
  • scale_x_comma: X & Y scales with opinionated presets for percent & comma label formats
  • scale_x_percent: X & Y scales with opinionated presets for percent & comma label formats
  • scale_y_comma: X & Y scales with opinionated presets for percent & comma label formats
  • scale_y_percent: X & Y scales with opinionated presets for percent & comma label formats

Palettes/Named Colors:

  • ipsum_pal: A muted, qualitative color palette
  • ft_cols: FT color palette
  • ft_pal: A bright qualitative color palette
  • ft_text_col: FT color palette

Fonts:

  • font_an: Arial Narrow font name R variable aliases
  • font_es: Econ Sans font name R variable aliases
  • font_es_bold: Econ Sans font name R variable aliases
  • font_es_light: Econ Sans font name R variable aliases
  • font_rc: Roboto Condensed font name R variable aliases
  • font_rc_light: Roboto Condensed font name R variable aliases
  • font_pub: Public Sans font name R variable aliases
  • font_pub_bold: Public Sans font name R variable aliases
  • font_pub_light: Public Sans font name R variable aliases
  • font_pub_thin: Public Sans font name R variable aliases
  • font_ps: PlexSans font name R variable aliases
  • font_ps_light: PlexSans font name R variable aliases

Utilities:

  • flush_ticks: Makes axis text labels flush on the ends
  • ft_geom_defaults: Change geom defaults from black to custom lights for the FT theme
  • gg_check: Spell check ggplot2 plot labels
  • import_econ_sans: Import Econ Sans Condensed font for use in charts
  • import_plex_sans: Import IBM Plex Sans font for use in charts
  • import_roboto_condensed: Import Roboto Condensed font for use in charts
  • modern_geom_defaults: Change geom defaults from black to white for the modern theme
  • update_geom_font_defaults: Update matching font defaults for text geoms

Installation

install.packages("hrbrthemes") # NOTE: CRAN version is 0.8.0
# or
remotes::install_gitlab("hrbrmstr/hrbrthemes")

NOTE: To use the ‘remotes’ install options you will need to have the {remotes} package installed.

Usage

library(hrbrthemes)
library(gcookbook)
library(tidyverse)

# current version
packageVersion("hrbrthemes")
## [1] '0.8.7'

Base theme (Arial Narrow)

ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  labs(x="Fuel efficiency (mpg)", y="Weight (tons)",
       title="Seminal ggplot2 scatterplot example",
       subtitle="A plot that is only useful for demonstration purposes",
       caption="Brought to you by the letter 'g'") + 
  theme_ipsum()

Roboto Condensed

ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  labs(x="Fuel efficiency (mpg)", y="Weight (tons)",
       title="Seminal ggplot2 scatterplot example",
       subtitle="A plot that is only useful for demonstration purposes",
       caption="Brought to you by the letter 'g'") + 
  theme_ipsum_rc()

New FT Theme!

ggplot(mtcars, aes(mpg, wt)) +
  geom_point(color = ft_cols$yellow) +
  labs(x="Fuel efficiency (mpg)", y="Weight (tons)",
       title="Seminal ggplot2 scatterplot example",
       subtitle="A plot that is only useful for demonstration purposes",
       caption="Brought to you by the letter 'g'") + 
  theme_ft_rc()

IBM Plex Sans

ggplot(mpg, aes(displ, hwy)) +
  geom_jitter(aes(color=class, fill=class), size=3, shape=21, alpha=1/2) +
  scale_x_continuous(expand=c(0,0), limits=c(1, 8), breaks=1:8) +
  scale_y_continuous(expand=c(0,0), limits=c(10, 50)) +
  scale_color_ipsum() +
  scale_fill_ipsum() +
  facet_wrap(~class, scales="free") +
  labs(
    title="IBM Plex Sans Test",
    subtitle="This is a subtitle to see the how it looks in IBM Plex Sans",
    caption="Source: hrbrthemes & IBM"
  ) +
  theme_ipsum_ps(grid="XY", axis="xy") +
  theme(legend.position="none") -> gg

flush_ticks(gg)
## theme(axis.text.x=element_text(hjust=c(0, rep(0.5, 6), 1))) +
## theme(axis.text.y=element_text(vjust=c(0, rep(0.5, 3), 1)))

Scales (Color/Fill)

ggplot(mtcars, aes(mpg, wt)) +
  geom_point(aes(color=factor(carb))) +
  labs(x="Fuel efficiency (mpg)", y="Weight (tons)",
       title="Seminal ggplot2 scatterplot example",
       subtitle="A plot that is only useful for demonstration purposes",
       caption="Brought to you by the letter 'g'") + 
  scale_color_ipsum() +
  theme_ipsum_rc()

Scales (Axis)

count(mpg, class) %>% 
  mutate(pct=n/sum(n)) %>% 
  ggplot(aes(class, pct)) +
  geom_col() +
  scale_y_percent() +
  labs(x="Fuel efficiency (mpg)", y="Weight (tons)",
       title="Seminal ggplot2 column chart example with percents",
       subtitle="A plot that is only useful for demonstration purposes",
       caption="Brought to you by the letter 'g'") + 
  theme_ipsum(grid="Y")

ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup)) + 
  geom_area() +
  scale_fill_ipsum() +
  scale_x_continuous(expand=c(0,0)) +
  scale_y_comma() +
  labs(title="Age distribution of population in the U.S., 1900-2002",
       subtitle="Example data from the R Graphics Cookbook",
       caption="Source: R Graphics Cookbook") +
  theme_ipsum_rc(grid="XY") +
  theme(axis.text.x=element_text(hjust=c(0, 0.5, 0.5, 0.5, 1))) +
  theme(legend.position="bottom")

update_geom_font_defaults(font_rc_light)

count(mpg, class) %>% 
  mutate(n=n*2000) %>% 
  arrange(n) %>% 
  mutate(class=factor(class, levels=class)) %>% 
  ggplot(aes(class, n)) +
  geom_col() +
  geom_text(aes(label=scales::comma(n)), hjust=0, nudge_y=2000) +
  scale_y_comma(limits=c(0,150000)) +
  coord_flip() +
  labs(x="Fuel efficiency (mpg)", y="Weight (tons)",
       title="Seminal ggplot2 column chart example with commas",
       subtitle="A plot that is only useful for demonstration purposes, esp since you'd never\nreally want direct labels and axis labels",
       caption="Brought to you by the letter 'g'") + 
  theme_ipsum_rc(grid="X")

Spellcheck ggplot2 labels

df <- data.frame(x=c(20, 25, 30), y=c(4, 4, 4), txt=c("One", "Two", "Three"))

ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  labs(x="This is some txt", y="This is more text",
       title="Thisy is a titlle",
       subtitle="This is a subtitley",
       caption="This is a captien") +
  theme_ipsum_rc(grid="XY") -> gg

gg_check(gg)
## Possible misspelled words in [title]: (Thisy, titlle)
## Possible misspelled words in [subtitle]: (subtitley)
## Possible misspelled words in [caption]: (captien)

hrbrthemes Metrics

Lang # Files (%) LoC (%) Blank lines (%) # Lines (%)
R 21 0.40 1548 0.41 290 0.5 915 0.5
SVG 4 0.08 310 0.08 0 0.0 0 0.0
JSON 1 0.02 15 0.00 0 0.0 0 0.0
SUM 26 0.50 1873 0.50 290 0.5 915 0.5

{cloc} 📦 metrics for hrbrthemes

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

hrbrthemes's People

Contributors

barnettjacob avatar benmarwick avatar bhaskarvk avatar gkampolis avatar hrbrmstr avatar jemus42 avatar jofam avatar karldw avatar mpancia avatar phillyo avatar xvrdm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hrbrthemes's Issues

Undefined exports: expand_scale

Using devtools::update_packages() I am getting an undefined exports error for expand_scale. Looking at the latest commit, the function is exported in the NAMESPACE file and the expand-scale.r file exists, but there's no function defined. Thanks!

Roboto Condensed Light not referencable on Windows

Under Windows 10 x64 Pro, installing the full set of Roboto Condensed styles (whether via hrbrthemes::import_roboto_condensed() or manual install and extrafont::font_import) will only register Roboto Condensed and not Roboto Condensed Light. This soft-breaks theme_ipsum_rc (warnings are generated and the relevant elements are not rendered correctly).

I believe this is due to style linking in the TTF files. Windows appears to be "helpfully" limiting the styles that are exposed (only the font family appears in other programs such as MS Word, etc.).

I've searched around and haven't found any resources on how to work around this. ☹️

font family not found in Windows font database

None of the fonts is working for me on Windows 10. I can use roboto and ibm plex (and Arial Narrow) outside of Rstudio.

This won't work for me, resulting in a plot with R's default font (vanilla Arial?)

library(hrbrthemes)
library(tidyverse)

import_roboto_condensed()

ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  labs(x="Fuel effiiency (mpg)", y="Weight (tons)",
       title="Seminal ggplot2 scatterplot example",
       subtitle="A plot that is only useful for demonstration purposes",
       caption="Brought to you by the letter 'g'") + 
  theme_ipsum_rc()

I'm using R 3.4.2, Rstudio 1.1.383 and the latest theme package ‘0.5.0’.

supporting applying `hrbrthemes` themes to labels in `ggplot2`

I noticed that, after applying the hrbrthemes, although the subtitle, title, caption, legend, axes-titles, etc. all change, the labels inside the plot remain unaffected. And I was wondering if it would be possible to also apply theming to this component of the plot.

Otherwise, there are two different font-families in the same plot, one for non-labels and one for labels.

Thanks for considering.

library(ggrepel)
#> Loading required package: ggplot2
library(ggplot2)
library(hrbrthemes)
#> NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
#>       Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
#>       if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow

p <- ggplot( mtcars, aes(wt, mpg, label = rownames(mtcars), colour = factor(cyl))) +
  geom_point() + 
  labs(title = "This is my title",
       subtitle = "This is my subtitle",
       caption = "This is my caption")

# without `hrbrthemes`
set.seed(123)
p + geom_label_repel() 
#> Warning: ggrepel: 14 unlabeled data points (too many overlaps). Consider
#> increasing max.overlaps

# with `hrbrthemes`
set.seed(123)
p + geom_label_repel() + hrbrthemes::theme_ipsum_tw()
#> Warning: ggrepel: 19 unlabeled data points (too many overlaps). Consider
#> increasing max.overlaps

Created on 2021-03-04 by the reprex package (v1.0.0)

Gridlines and Grid Labels are Out of Alignment

Hi! I appreciate the work that went into this because it makes it much easier to put my analysis into a ready-state to share with stakeholders. I wanted to bump up this small nit.

It looks like the y-axis labels aren't in alignment with the y-axis grid.

Here's the code to generate these plots:

library(tidyverse)
library("hrbrthemes")

df <- data.frame(
  name = c("bookshelf", "coffee table", "snowglobe"),
  value = c(100, 28, 13)
)

df %>% 
  ggplot(aes(name, value)) +
  geom_col() +
  theme_ipsum_rc(grid = "y")

Screen Shot 2020-04-15 at 10 27 04 PM

Screen Shot 2020-04-15 at 10 27 20 PM

Errors installing

Installing from both CRAN and Github producing errors.

# Install {hrbrthemes}
devtools::install_github("hrbrmstr/hrbrthemes")
#> Downloading GitHub repo hrbrmstr/hrbrthemes@master
#> 
#>   
   checking for file/private/var/folders/44/hrlycnxd6zj2sn49bxrp2_6c0000gn/T/RtmpBHNaOD/remotes11e72a1dc133/hrbrmstr-hrbrthemes-5b0b743/DESCRIPTION...checking for file/private/var/folders/44/hrlycnxd6zj2sn49bxrp2_6c0000gn/T/RtmpBHNaOD/remotes11e72a1dc133/hrbrmstr-hrbrthemes-5b0b743/DESCRIPTION#> preparinghrbrthemes:
#> 
  
   checking DESCRIPTION meta-information ...checking DESCRIPTION meta-information
#> checking for LF line-endings in source and make files and shell scripts
#> checking for empty or unneeded directories
#> ─  building ‘hrbrthemes_0.6.0.tar.gz’
#> 
  
   
#> 
#> Error in i.p(...): (converted from warning) installation of package '/var/folders/44/hrlycnxd6zj2sn49bxrp2_6c0000gn/T//RtmpBHNaOD/file11e725420dd54/hrbrthemes_0.6.0.tar.gz' had non-zero exit status

Created on 2019-01-23 by the reprex package (v0.2.1)

Session info:

sessionInfo()
#> R version 3.5.2 (2018-12-20)
#> Platform: x86_64-apple-darwin15.6.0 (64-bit)
#> Running under: macOS Mojave 10.14.2
#> 
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] compiler_3.5.2  magrittr_1.5    tools_3.5.2     htmltools_0.3.6
#>  [5] yaml_2.2.0      Rcpp_1.0.0      stringi_1.2.4   rmarkdown_1.11 
#>  [9] highr_0.7       knitr_1.21      stringr_1.3.1   xfun_0.4       
#> [13] digest_0.6.18   evaluate_0.12

Created on 2019-01-23 by the reprex package (v0.2.1)

gdtools dependency/suggests no more needed

Hello Bob,

The package suggests and uses gdtools because it uses vdiffr, vdiffr is not using gdtools anymore, I think it should be removed.

(I can PR if you agree :) )

KR
David

RC font not rendering in shiny

I have a shiny app with Roboto Condensed being the primary font. It links to a CSS stylesheet with the appropriate RC google fonts URL imported in:

@import url('https://fonts.googleapis.com/css?family=Roboto+Condensed');

It works on all <h> and <p> elements in the app but a ggplot with the ipsum_rc theme set is not rendering the rc font.

You can see the app here. and source code here.

Thanks!

More thorough font installation/config documentation & helpers

Many of the issues filed for this package are unsurprisingly font related.

To help alleviate or even prevent these issues, the package needs:

  • better documentation on fonts
  • platform-specific helpers for installation & triage
  • robust platform detection (down to version & patch level) to ensure the right font names are used on the right platform since legacy operating systems like Windows mangle things pretty badly

Mismatch between supplied theme_ipsum_rc and sample graphs

The demo plots for theme_ipsum_rc both here and on your blog seem to be using a lighted panel.grid color value that what's at https://github.com/hrbrmstr/hrbrthemes/blob/master/R/roboto-condensed.r#L74-L76. On my test installs (yes, Windows 10 🤷‍♂️ ) it looks like the supplied color value should be grey80 (or its moral equivalent).

Can you verify the current value of #2b2b2b99 is the desired default? Sample from my install included below for reference.

heavy_lines

Problems with registering Roboto Condensed on macOS

I suggest integrating the following piece of code in the import_roboto_condensed() function, after running extrafont::font_import():

d <- read.csv(extrafont:::fonttable_file(), stringsAsFactors = FALSE)
d[grepl("Light", d$FontName), ]$FamilyName <- font_rc_light  # "Roboto Condensed Light"
write.csv(d, extrafont:::fonttable_file(), row.names = FALSE)

extrafont::loadfonts()

What the code does is to change the family of Roboto Condensed Light and Roboto Condensed Light Italic stored in the fonttable CSV file from Roboto Condensed to Roboto Condensed Light. This operation is needed, because otherwise extrafont::loadfonts() would detect duplicate fonts, and it would be impossible to export a plot (e.g., through ggsave()).

This solves problems similar to #2.

theme_modern_rc has dark strip.text on dark background

Strip text on facetted plots is a bit hard to make out.

library(ggplot2)
library(hrbrthemes)
packageVersion("hrbrthemes")
#> [1] '0.6.0'

ggplot(mtcars, aes(mpg, hp)) +
  geom_point() +
  facet_wrap(~cyl) +
  theme_modern_rc() +
  labs(title = "Look, a plot",
       subtitle = "Something's off though",
       caption = "Wher's my strip text?")

Created on 2019-03-31 by the reprex package (v0.2.1)

The example charts contain a different fill than the defaults

Hi! I replicated this code in my Rstudio instance and the coloring is somewhat different.

This code block produces a bar with dark grey fill (#595959) and the example chart shows bars with a light grey fill (#667a87). Would you mind making a note on how you changed the defaults?

Dark (FT) Roboto RMarkdown template

Hi @hrbrmstr

I've created a dark (FT-based) Roboto R markdown template called FT (based on the existing ipsum HTML template); perhaps this is useful for others as well so I've submitted a PR.

It only works for HTML output (a dark PDF theme doesn't really make sense IMO).

Upon installation, it should show up as a template

Screen Shot 2019-11-15 at 11 48 54 am

knitting then gives

Screen Shot 2019-11-15 at 11 49 33 am

**CLOSE** Mac Change Font Family

Hello,

I'm having a tough time figuring out how to add a new font family for ggplots for Mac. In particular, I'm using the theme_ipsum() function for my ggplots in my report. I'd like to use the Century Gothic font family to match the rest of my text. Does anyone know how to do this?

Thanks!

PDF Output

Hi,

I would like to use hrbdthemes with a PDF output Rmarkdown document. Truing this simple example :

---
title: "hrbrthemes testbed"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(hrbrthemes)
library(tidyverse)

Arial Narrow

ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title="Arial Narrow", subtitle="This is a subtitle") +
  theme_ipsum()

Roboto Condensed

ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title="Roboto Condensed", subtitle="This is a subtitle") +
  theme_ipsum_rc()

I get the following error : 

`Error in grid.Call.graphics : incorrect font specification.`

How can I fix this ?

What's next?

@bhaskarvk now needs to get some font pkgs on CRAN :-)

  • Expand vignette
  • Add example images in Rd
  • Transcribe log of all the extra tweaks I do and see if any warrant creating a hrbrthemes shortcut
  • …?

Ipsum Roboto HTML Template

Hi,

Please help since I am unable to knit ipsum Roboto template.

pandoc: Could not fetch https://fonts.googleapis.com/css?family=Roboto+Slab:100,300,400,700
TlsExceptionHostPort (HandshakeFailed (Error_Misc "user error (unexpected type received. expecting handshake and got: Alert [(AlertLevel_Fatal,HandshakeFailure)])")) "fonts.googleapis.com" 443
Error: pandoc document conversion failed with error 67
Execution halted

I check the font link directly and it is fine.

Here is my sessionInfo()

R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] hrbrthemes_0.6.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0       git2r_0.23.0     pillar_1.3.0     compiler_3.5.1   plyr_1.8.4       bindr_0.1.1      tools_3.5.1     
 [8] extrafont_0.17   digest_0.6.18    evaluate_0.12    memoise_1.1.0    tibble_1.4.2     gtable_0.2.0     pkgconfig_2.0.2 
[15] rlang_0.3.0.1    rstudioapi_0.8   curl_3.2         yaml_2.2.0       bindrcpp_0.2.2   Rttf2pt1_1.3.7   httr_1.3.1      
[22] withr_2.1.2      dplyr_0.7.8      knitr_1.20       gdtools_0.1.7    devtools_1.13.6  rprojroot_1.3-2  grid_3.5.1      
[29] tidyselect_0.2.5 glue_1.3.0       R6_2.3.0         rmarkdown_1.11   ggplot2_3.1.0    purrr_0.2.5      extrafontdb_1.0 
[36] magrittr_1.5     backports_1.1.2  scales_1.0.0     htmltools_0.3.6  assertthat_0.2.0 colorspace_1.3-2 lazyeval_0.2.1  
[43] munsell_0.5.0    crayon_1.3.4  

Forthcoming release of ggplot2 and hrbrthemes

We are contacting you because you are the maintainer of hrbrthemes, which imports ggplot2 and uses vdiffr to manage visual test cases. The upcoming release of ggplot2 includes several improvements to plot rendering, including the ability to specify lineend and linejoin in geom_rect() and geom_tile(), and improved rendering of text. These improvements will result in subtle changes to your vdiffr dopplegangers when the new version is released.

Because vdiffr test cases do not run on CRAN by default, your CRAN checks will still pass. However, we suggest updating your visual test cases with the new version of ggplot2 as soon as possible to avoid confusion. You can install the development version of ggplot2 using remotes::install_github("tidyverse/ggplot2").

If you have any questions, let me know!

theme_ipsun fonts not working

I am not being able to apply extra fonts when using the theme_ispun fucntion (theme_ipsun_rc specifically).
Steps I have followed:

  1. Dowonload and isntall fonts from google fonts (Roboto Condenced).
  2. Import new fonts in Rstudio using extrafont::font_import( ) function.
  3. Load new fonts in Rstudio using extrafont::loadfonts( ) function. As an alternative I used extrafont::loadfonts(device = "win")
  4. Apply the theme_ipsum_rc( ) function on a ggplot command

The theme_ipsun_rc( ) is working; however, the font is not being applied. There is no error or warning at any point.

Any suggestion about what else can I do?

panel.spacing set for x and y

theme_ipsum contains the following two lines (line 155&156):

ret <- ret + theme(panel.spacing.x = grid::unit(2, "lines"))
ret <- ret + theme(panel.spacing.y = grid::unit(2, "lines"))

Is there a reason panel.spacing is not set instead? The x and y inherit from that anyways, and the value set is the same.

The current use can be confusing as theme_ipsum() + theme(panel.spacing = grid::unit(100, 'lines')) will actually have no effect.

pdf output uses Adobe Serif MM instead of Roboto or Arial Narrow

I am trying to get PDF files using ggsave. PNG files work correctly and display the fonts I want to use like Roboto or Arial Narrow. But when I try PDF output using Acrobat Reader, the PDF file properties list RobotoCondensed being used, but the Actual Font as Adobe Serif. See below

image

As you can imagine, it's pretty ugly!

image

What could be causing this?

One clue is something wrong with Acrobat Reader. I tried looking at the file with SumatraPDF and it showed Roboto Condensed output just fine. When I was working with a LaTeX compiler, the preview window also displayed the file with the correct font. But not Acrobat Reader. This is a problem, as Reader is the most common software for reading PDFs!

Lighter color on grids

Hi,
I have seen people use the hrbrthemes and immediately change the

theme(panel.grid.major=element_line(color="#cccccc"))
theme(panel.grid.minor=element_line(color="#cccccc"))

or even lighter (#d9d9d9 or #e6e6e6). Last value is probably too light on print, but default 17% grey looks noisy, especially on things like geom_boxplot(). Have you considered lighter colors for grid?

Arial is used instead of arial narrow on linux?

This is more like an "am I the only one?" question. :)

I just deployed a shiny app to a rstudio connect server on a linux machine and I noticed that the font on the web app is a lot larger on the web app than it appears on my local machine. It seems like it's using arial instead of arial narrow, maybe?

Then, I installed Arial Narrow to that linux box manually and I also tried out to use the extrafont package but I haven't fixed the problem. Do you have any idea what I should do? Even though arial doesn't look horrible, I do very much like the "narrowed" version.

web app..........local app under the same zooming rate, using the same code
screen shot 2017-03-08 at 5 22 53 pmscreen shot 2017-03-08 at 5 23 20 pm

Dot Plots in hrbrthemes

Hi Bob! Would you be open to giving me pointers on how to add a dotplot to hrbrthemes? Would love to show dot plots for displaying amounts where there are more than six categories.

Would love to get your thinking here!

Let me know! 😃

Source: Example is on Page 54 from Fundamentals of Data Visualization: A Primer on Making Informative and Compelling Figures by Claus O. Wilke and I hold no copyright.

Allow labels to be NULL for `gg_check()`?

hrbrthemes::gg_check() works like magic:

library(ggplot2)

ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  labs(x = "This is some txt", 
       title = "Thisy is a titlle") -> gg
hrbrthemes::gg_check(gg)
#> Possible misspelled words in [title]: (Thisy, titlle)

But hrbrthemes::gg_check() fails to check the typo in title when x = NULL:

ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  labs(x = NULL, 
       title = "Thisy is a titlle") -> gg
hrbrthemes::gg_check(gg)
#> Error: is.character(text) is not TRUE

theme_modern_rc() overwrites default point color

Hi Bob, thanks for your great package(s)!

I just realized, that when I call theme_modern_rc() once all my following plots have light blue dots without specifying it. I was able to track it down to your theme but it also happens when I add it via namespace and is still present after detaching the package. How can one overcome this? I think the expected behavior is to replace the color when using the theme but keep em black by default in all other cases.

Cheers,
Cédric

Error: lazy-load database ... hrbrthemes.rdb' is corrupt

I was working on an R file, and I saw th message below pop up in the console. I wasn't actively using any of the functions from the package, however the only related thing I can think of, is that the file I was working on was my own themes definitions (however, not inheriting or basing it off of the themes in hrbrthemes).

The error that I am seeing in the RStudio console is:
Error: lazy-load database '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/hrbrthemes/R/hrbrthemes.rdb' is corrupt
In addition: Warning message:
internal error -3 in R_decompress1
Error: lazy-load database '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/hrbrthemes/R/hrbrthemes.rdb' is corrupt
In addition: Warning messages:
1: restarting interrupted promise evaluation
2: internal error -3 in R_decompress1

Installed via: remotes::install_github("hrbrmstr/hrbrthemes")
R version: 4.0.2
OS: Catalina 10.15.5 (19F101)

Let me know if there is any other information I can provide to help debug.

Registering fonts on windows

I am unable to use Roboto Condensed on windows unless I first attach the extrafont package, which you can see has some windows special sauce:

.onAttach <- function(libname, pkgname) {
    packageStartupMessage("Registering fonts with R")

    ## Load all fonts
    loadfonts("pdf", quiet = TRUE)
    loadfonts("postscript", quiet = TRUE)
    if (.Platform$OS.type == "windows") {
        loadfonts("win", quiet = TRUE)
    }
}

After loading extrafont, all works well

Warning in RMarkdown

 In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font family 'Arial Narrow' not found in PostScript font database

Same as hrbrmstr/hrbrmisc#3, but this time with correct family name of Arial Narrow instead of ArialNarrow.

Gridlines and Axis Labels are Out of Alignment

Hi! I appreciate the work that went into this because it makes it much easier to put my analysis into a ready-state to share with stakeholders. I wanted to bump up this small nit.

It looks like the y-axis labels aren't in alignment with the y-axis gridlines.

Here's the code to generate these plots:

library(tidyverse)
library("hrbrthemes")

df <- data.frame(
  name = c("bookshelf", "coffee table", "snowglobe"),
  value = c(100, 28, 13)
)

df %>% 
  ggplot(aes(name, value)) +
  geom_col() +
  theme_ipsum_rc(grid = "y")

Here's the plots:

Screen Shot 2020-04-15 at 10 27 04 PM

Screen Shot 2020-04-15 at 10 27 20 PM

Found a typo in pkgdown

I found a typo in pkgdown: missing one quotation mark.

install.packages("hrbrthemes) # NOTE: CRAN version is 0.8.0

스크린샷 2024-01-09 오전 9 55 40

The plot does't work for Chinese font family

theme(text = element_text(family = "STKaiti")) is a way to show Chinese font on the plot. I find it cannot work with function theme_ipsum().

> library(hrbrthemes)
> library(gcookbook)
> library(tidyverse)
> 
> # current verison
> packageVersion("hrbrthemes")
[1] ‘0.5.0’
> ggplot(mtcars, aes(mpg, wt)) +
+   geom_point() +
+   labs(x="燃油效率", y="重量,单位吨",
+        title="散点图例子",
+        subtitle="就是用用中文而已",
+        caption="数据来自tidyverse, mtcars") +
+   theme_ipsum() +
+   theme(text = element_text(family = "STKaiti"))


But for other ggplot theme, like theme_minimal(), this way works well.

ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  labs(x="燃油效率", y="重量,单位吨",
       title="散点图例子",
       subtitle="就是用用中文而已",
       caption="数据来自tidyverse, mtcars") +
  # theme_ipsum() +
  theme_minimal() +
  theme(text = element_text(family = "STKaiti"))
  ggsave("theme_minimal.png",device = "png")


Here is my sessionInfo()

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] forcats_0.3.0    stringr_1.3.0    dplyr_0.7.4      purrr_0.2.4     
 [5] readr_1.1.1      tidyr_0.8.0      tibble_1.4.2     ggplot2_2.2.1   
 [9] tidyverse_1.2.1  gcookbook_1.0    hrbrthemes_0.5.0 optparse_1.4.4  

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.16     lubridate_1.7.3  lattice_0.20-35  assertthat_0.2.0
 [5] rprojroot_1.2    digest_0.6.12    psych_1.7.8      mime_0.5        
 [9] R6_2.2.2         cellranger_1.1.0 plyr_1.8.4       backports_1.1.0 
[13] reprex_0.1.2     evaluate_0.10.1  httr_1.3.1       pillar_1.2.1    
[17] rlang_0.2.0      lazyeval_0.2.1   readxl_1.0.0     miniUI_0.1.1    
[21] rstudioapi_0.7   extrafontdb_1.0  rmarkdown_1.9    labeling_0.3    
[25] extrafont_0.17   foreign_0.8-69   munsell_0.4.3    shiny_1.0.5     
[29] broom_0.4.3      compiler_3.4.4   httpuv_1.3.6.2   modelr_0.1.1    
[33] pkgconfig_2.0.1  mnormt_1.5-5     htmltools_0.3.6  crayon_1.3.4    
[37] grid_3.4.4       nlme_3.1-131.1   jsonlite_1.5     xtable_1.8-2    
[41] Rttf2pt1_1.3.6   gtable_0.2.0     magrittr_1.5     scales_0.5.0    
[45] cli_1.0.0        stringi_1.1.7    reshape2_1.4.3   bindrcpp_0.2    
[49] getopt_1.20.2    xml2_1.2.0       tools_3.4.4      glue_1.2.0      
[53] hms_0.4.2        parallel_3.4.4   yaml_2.1.18      colorspace_1.3-2
[57] rvest_0.3.2      knitr_1.20       bindr_0.1        haven_1.1.1 

Add detection for consistency in plot labels

Let's say I want to make sure that all my labels are the same. In the following example, the word 'text' is spelled differently on the x-axis and the y-axis (and you could argue it is spelled incorrectly on the x-axis):

ggplot(mtcars, aes(mpg, wt)) +
    geom_point() +
    labs(x="This is some txt", y="This is more text",
         title="Thisy is a titlle",
         subtitle="This is a subtitley",
         caption="This is a captien") +
    theme_ipsum_rc(grid="XY") -> gg

gg_check(gg)

gg_check(gg) picks up that 'Thisy', 'titlle', and 'subtitley' are misspelled, but not that 'txt' is misspelled (even though it is an abbreviation) or that there is another instance of the same word on the plot. I can see an argument for not suggesting that abbreviations are misspellings, but detecting for consistency would be great!

Above code is from here.

Paris

Kern-what?

Kerning is nothing more than a fancy word for spaces between letters and fonts have built-in tables for how various paris of letters should be placed next to each other.

Install errors

Install works fine, but when I try to add hrbrthemes to and get the following error:

> library(hrbrthemes) Error: package or namespace load failed for ‘hrbrthemes’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/Library/Frameworks/R.framework/Versions/3.6/Resources/library/systemfonts/libs/systemfonts.so': dlopen(/Library/Frameworks/R.framework/Versions/3.6/Resources/library/systemfonts/libs/systemfonts.so, 6): Library not loaded: /opt/X11/lib/libfreetype.6.dylib Referenced from: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/systemfonts/libs/systemfonts.so Reason: image not found

Any help would be appreciated.

hrbrthemes::theme_ipsum_rc(), issue

I keep getting this error when I run this hrhrthemes code for a ggplot

Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
polygon edge not found

Unable to export to pdf for some fonts

I'm unable to save to PDF using anything other than Arial Narrow. This is similar to #2, but the fixes there don't work for me.

I've:

  1. Imported and installed fonts
library(hrbrthemes)
import_public_sans()
import_titillium_web() 
import_econ_sans() 
import_tinyhand() 
import_plex_sans()
import_roboto_condensed()
  1. Installed these imported fonts using FontBook (on Mac)
  2. Checked fonts are loaded:
> fonts()
  [1] "Roboto Condensed"        "Public Sans Black"       "Public Sans"             "Public Sans ExtraBold"   "Public Sans ExtraLight"  "Public Sans Light"      
  [7] "Public Sans Medium"      "Public Sans SemiBold"    "Public Sans Thin"        "Titillium Web"           "Titillium Web Light"     "EconSansCndBol"         
 [13] "EconSansCndBolIta"       "EconSansCndLig"          "EconSansCndLigIta"       "EconSansCndMed"          "EconSansCndMedIta"       "EconSansCndReg"         
 [19] "EconSansCndRegIta"       "BF Tiny Hand"            "IBM Plex Sans"           "IBM Plex Sans Light"     "IBM Plex Sans Medium"    "IBM Plex Sans Text"     
 [25] "IBM Plex Sans Thin" 

But I still get an error when trying to save to pdf when using theme_ipsum_rc():

extrafont::loadfonts(quiet=TRUE, device='pdf')
g <- iris %>% ggplot(aes(Sepal.Length, Sepal.Width)) + geom_point() + theme_ipsum_rc() + labs(caption='Caption')
g
ggsave('temp.pdf', g)

Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, : invalid font type

Saving to png works fine.

Somehow the PDF device doesn't see the installed fonts, but after much searching I can't find the solution. Any tips greatly appreciated!

Reproducible example (.Rmd):

---
title: "test"
output: 
  rmdformats::readthedown:
     lightbox: true
     gallery: true
     fig_caption: true
     code_folding: "hide"
     code_download: true
     use_bookdown: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(dev=c('png', 'pdf'),  comment="", fig.width=12, echo=T, warning=FALSE, cache=F, message=FALSE,  fig.path='figure/theme_test/')
library(hrbrthemes)
library(tidyverse)
extrafont::loadfonts(quiet=TRUE, device='pdf')
library(ggplot2)
 ```  `

```{r }
g <- iris %>% ggplot(aes(Sepal.Length, Sepal.Width)) + geom_point() + theme_ipsum_rc() + labs(caption='Caption')
g
ggsave('temp.pdf', g)
``` .

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.15.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_NZ.UTF-8/en_NZ.UTF-8/en_NZ.UTF-8/C/en_NZ.UTF-8/en_NZ.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] extrafont_0.17   forcats_0.5.0    stringr_1.4.0    dplyr_1.0.2      purrr_0.3.4      readr_1.3.1      tidyr_1.0.2      tibble_3.0.3     ggplot2_3.3.2   
[10] tidyverse_1.3.0  hrbrthemes_0.8.0

loaded via a namespace (and not attached):
  [1] colorspace_1.4-1     pryr_0.1.4           ellipsis_0.3.1       ggridges_0.5.2       brms_2.12.9          rsconnect_0.8.8      markdown_1.1        
  [8] fs_1.5.0             base64enc_0.1-3      rstudioapi_0.11      farver_2.0.3         rstan_2.19.3         DT_0.15              fansi_0.4.1         
 [15] mvtnorm_1.1-1        lubridate_1.7.4      xml2_1.3.2           bridgesampling_1.0-0 codetools_0.2-15     knitr_1.29           shinythemes_1.1.1   
 [22] bayesplot_1.7.1      projpred_2.0.0       jsonlite_1.7.0       packrat_0.4.9-3      broom_0.5.6          Rttf2pt1_1.3.8       dbplyr_1.4.3        
 [29] shiny_1.4.0.2        httr_1.4.2           compiler_3.5.1       backports_1.1.9      assertthat_0.2.1     Matrix_1.2-14        fastmap_1.0.1       
 [36] cli_2.0.2            later_1.1.0.1        htmltools_0.5.0      prettyunits_1.1.1    tools_3.5.1          igraph_1.2.2         coda_0.19-3         
 [43] gtable_0.3.0         glue_1.4.2           reshape2_1.4.3       Rcpp_1.0.5           cellranger_1.1.0     vctrs_0.3.4          nlme_3.1-137        
 [50] extrafontdb_1.0      crosstalk_1.1.0.1    insight_0.9.1.1      xfun_0.16            ps_1.3.4             summarytools_0.9.6   rvest_0.3.6         
 [57] openxlsx_4.1.4       mime_0.9             miniUI_0.1.1.1       lifecycle_0.2.0      gtools_3.8.1         zoo_1.8-7            scales_1.1.1        
 [64] colourpicker_1.0     hms_0.5.3            promises_1.1.1       Brobdingnag_1.2-6    parallel_3.5.1       inline_0.3.15        shinystan_2.5.0     
 [71] yaml_2.2.1           gridExtra_2.3        pander_0.6.3         gdtools_0.2.1        loo_2.2.0            StanHeaders_2.21.0-5 stringi_1.4.6       
 [78] bayestestR_0.7.2.1   dygraphs_1.1.1.6     checkmate_1.8.5      pkgbuild_1.1.0       zip_2.0.4            rlang_0.4.7          pkgconfig_2.0.3     
 [85] systemfonts_0.1.1    matrixStats_0.56.0   evaluate_0.14        lattice_0.20-35      labeling_0.3         rstantools_2.0.0     rapportools_1.0     
 [92] htmlwidgets_1.5.1    processx_3.4.3       tidyselect_1.1.0     plyr_1.8.6           magrittr_1.5         R6_2.4.1             magick_2.3          
 [99] generics_0.0.2       DBI_1.0.0            withr_2.2.0          haven_2.2.0          pillar_1.4.6         xts_0.12-0           abind_1.4-5         
[106] performance_0.4.8.1  modelr_0.1.6         crayon_1.3.4         rmarkdown_2.1        readxl_1.3.1         grid_3.5.1           callr_3.4.3         
[113] threejs_0.3.1        reprex_0.3.0         digest_0.6.25        xtable_1.8-4         httpuv_1.5.2         RcppParallel_5.0.2   stats4_3.5.1        
[120] munsell_0.5.0        tcltk_3.5.1          shinyjs_1.0  

Arial Narrow is not a family

Not sure if it is only on my Windows 7 PC, but Arial Narrow is not its own family. It is a member of the Arial family and regardless of my attempts I could not make it to show in the list of installed fonts as a separate items. Had to enforce mapping like this.

if (is.null(unlist(windowsFonts("Arial Narrow"))))
      windowsFonts(`Arial Narrow`=windowsFont("TT Arial Narrow"))
if (is.null(unlist(windowsFonts("Roboto Condensed"))))
      windowsFonts(`Roboto Condensed`=windowsFont("TT Roboto Condensed"))
if (is.null(unlist(windowsFonts("Roboto Condensed Light"))))
      windowsFonts(`Roboto Condensed Light`=windowsFont("TT Roboto Condensed Light"))

Is there a better way to check and enforce the mapping?

Side question: is there a way to force font family into annotations, text and labels (including repel) in one go?

References:
https://journal.r-project.org/archive/2015-1/qiu.pdf
http://blog.revolutionanalytics.com/2012/09/how-to-use-your-favorite-fonts-in-r-charts.html

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.