0

I'm creating an image using ggplot2 and ggiraph to my API in plumber.

I am using RStudio on Windows.

When I create an local API (that plumber provides in Swagger) everything seems ok to me.

But, when i use my Docker File with the command docker compose build api and then docker compose up ap for an Ubuntu image, the center dont look well.

By center i mean the arg hjust = 0.5

Right below is a piece of my image.

enter image description here

Both annotate and geom_text() works locally in my RStudio, but when i use my docker image, the centering dont looks well.

The labels start in center, but when use more and more characters, the string start going to the left.

The code for geom_text and annotate:

      [...] +

      geom_text(data=data.frame(), 
                aes(label = 'aaaaaaaaaaa', 
                    x = mean(c(df_user$xmin, df_user$xmax)),
                    y = ymax_rect - (2/7)*(ymax_rect - ymin_rect)),
                hjust = 0.5) +
      
      annotate("text",
               size = text_size,
               label = "a",
               color = "#E9EAF9",
               x = mean(c(df_user$xmin, df_user$xmax)),
               y = ymin_rect + (2/7)*(ymax_rect - ymin_rect),
               hjust = 0.5)

I'm start thinking if there is some lib/dependency that i need to install on my docker image to centering labels work properly (that maybe RStudio already does to me, without my knowledge)

The libs I alredy installed are:

FROM rocker/r-ver:4.0.2 as base

# Install gcsfuse
RUN apt-get update && apt-get install gnupg curl fuse -y && apt-get install -y wget
ENV GCSFUSE_REPO=gcsfuse-stretch
RUN apt-get update -y
RUN curl -L -O https://github.com/GoogleCloudPlatform/gcsfuse/releases/download/v0.30.0/gcsfuse_0.30.0_amd64.deb
RUN dpkg --install gcsfuse_0.30.0_amd64.deb
RUN apt-get remove -y curl --purge && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*

# Pandoc
RUN wget https://github.com/jgm/pandoc/releases/download/2.9.2.1/pandoc-2.9.2.1-1-amd64.deb
RUN dpkg -i pandoc-2.9.2.1-1-amd64.deb

# install the linux libraries needed for plumber
RUN apt-get update -qq && apt-get install -y \
  libssl-dev \
  libcurl4-gnutls-dev
  #libpq-dev # This for RPostgreSQL, if we need someday to use

Any suggestion will help. Thanks!

  • I think you are not using the font you are using locally. See https://davidgohel.github.io/ggiraph/articles/offcran/customizing.html#fonts-1. Use roboto font for example, and make it is available in your container so that R/ggiraph can compute correct font metrics – David Gohel Jan 12 '21 at 17:17
  • (I did not test it) I think `apt install fonts-roboto` will do the job to install roboto in your docker – David Gohel Jan 12 '21 at 17:19
  • I didnt set any font to my plot, i am using the default that ggplot2 choose to me. You think i need install roboto font anyway? – André Ambrósio Jan 12 '21 at 17:52
  • @DavidGohel forgot to mentioned you, sorry – André Ambrósio Jan 12 '21 at 18:03
  • The section here https://davidgohel.github.io/ggiraph/articles/offcran/customizing.html#fonts-1 explains things with fonts. – David Gohel Jan 12 '21 at 20:07

0 Answers0