rfortherestofus / omni

RMarkdown template, ggplot2 theme, and table function for OMNI Institute
https://rfortherestofus.github.io/omni/
Other
21 stars 5 forks source link

Unable to interactively make ggplots #86

Open dgkeyes opened 4 months ago

dgkeyes commented 4 months ago

Video explanation of issue

@OskaratOmni can you please use the code below to make a new R Markdown document and let me know if this works? Here's a video explanation of a couple things to try as well.

---
title: "OMNI Plot"
author: "David Keyes"
date: "2024-06-28"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(omni)
xx = runif(100, 1, 100)

d_data = data.frame(
  x = xx,
  y = .5 * xx + 2
)

ggplot(d_data, aes(x, y)) +
  geom_point() +
  theme_omni()
dgkeyes commented 4 months ago

Also, the video recording of our last call is here.

OskaratOmni commented 4 months ago

Hey @dgkeyes I just tried this both ways - with and without theme_omni and going to the console and inline.

In all cases when I call theme_omni() i only get a blank square (inline or in the viewer).

I just uploaded a video showing this as well. I know its weird behavior so it might help to see it with your own eyes. :-)

One other thing I tried is adding library(ragg) to the packages and that didn't seem to make a difference.

OskaratOmni commented 4 months ago

@dgkeyes , I uploaded a second video. Now if I switch global settings back to default, from AGG, on the backend graphics device, it works.

I find this really puzzling but wanted you to see that.

dgkeyes commented 4 months ago

Ok, so just to summarize:

With AGG set as the backend graphics device in RStudio:

With the default backend graphics device:

Is that all accurate?

One other question: what version of RStudio do you have? If it's not the newest version, could you update it and let me know if that changes anything?

OskaratOmni commented 4 months ago

Hey @dgkeyes, My first thought was 'yes' this is all correct, but I played with it a little more and so this is current as you've written it with one additional wrinkle. If I set base_family in the them_omni() call to something really basic, like "Arial" the graph will show up interactively with the backend set to AGG. It doesn't show up if it uses Calibri.

It wasn't that long ago that I downloaded fonts, but maybe they get removed at some point during some package downloads? Not sure. But I can double check that.

I am using the current version of R studio.

dgkeyes commented 4 months ago

Can you try using a different font? Try doing theme_omni(base_family = "Times New Roman") and see what happens. I'm working if it's specific to Calibri or something else.

OskaratOmni commented 4 months ago

Hey @dgkeyes I have tried it with Times New Roman and Arial, and in both cases it works interactively. And it seems to display them with the correct fonts when I have backend set to AGG. (the fonts look the same interactively when i have backend set to default).

With backend set to AGG if I try to make a figure with Calibri I got this message ONE time: Warning message: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font family not found in Windows font database

When I knit, it shows all kinds of warnings about font family for all three of the fonts I tried (Calibri, Times New Roman, and Arial). And it looks like the knitted file is not showing the correct font.

Weird, huh?

dgkeyes commented 4 months ago

Ok, this is actually really helpful. It seems that R isn't finding the Calibri font, which explains why this isn't working. Try running this code:

library(tidyverse)
library(systemfonts)

system_fonts() |> 
  filter(str_detect(family, "Calibri"))

That will show whether the systemfonts package finds any fonts named Calibri. The output I get is:

# A tibble: 4 × 9
  path                                                    index name   family style weight width italic monospace
  <chr>                                                   <int> <chr>  <chr>  <chr> <ord>  <ord> <lgl>  <lgl>    
1 /Users/davidkeyes/Library/Fonts/Calibri.ttf                 0 Calib… Calib… Regu… normal norm… FALSE  FALSE    
2 /Users/davidkeyes/Library/Fonts/Calibri Bold Italic.ttf     0 Calib… Calib… Bold… bold   norm… TRUE   FALSE    
3 /Users/davidkeyes/Library/Fonts/Calibri Italic.ttf          0 Calib… Calib… Ital… normal norm… TRUE   FALSE    
4 /Users/davidkeyes/Library/Fonts/Calibri Bold.ttf            0 Calib… Calib… Bold  bold   norm… FALSE  FALSE   

Please paste your output in the issue and we can go from there.

OskaratOmni commented 4 months ago

I haven't done this yet but I bet it works. All the behavior was suggesting to me that the Calibri font got 'dropped' or uninstalled, perhaps as part of a cycle of package updates or something like that. I'll get back t o you ASAP.