1

I cannot right align the y-axis labels in this shiny app using ggiraph.

Please find the running app here, a picture of the issue, the code, and app: https://eduardo757ag.shinyapps.io/test_labels/

I tried with theme(axis.text.y = element_text(hjust=1)) to no avail.

Thanks for your help!

enter image description here


title: "test1" author: "edu" date: '' output: html_document: highlight: tango theme: journal runtime: shiny


library(tidyverse)
library(ggiraph)
library(shiny)
library(survey)

data(api)

api_test <- apiclus1 %>% 
  dplyr::group_by(cname) %>% 
  dplyr::summarise_at(vars(acs.k3:acs.46), mean,na.rm=T) %>% 
  pivot_longer(2:3,names_to = "variable",values_to = "value") %>% 
  dplyr::mutate(    
    IOMmission = 
      case_when(cname=="Alameda" ~ "A very very long long label, yes",
                T~cname))

api_test$tooltip <- c(paste0(api_test$cname, "\n", api_test$value))

shinyApp(

  # ui.R ----
ui <- fluidPage(
    sidebarLayout(

        sidebarPanel(
          selectInput(inputId = "Variable",
                        label = "Select a survey question",
                        choices= unique(api_test$variable)),

          width = 4,
          style = "font-family: 'Georgia'"),

        mainPanel(
          girafeOutput("mygplot1"),
          width = 8))
),

# server.R ----
server <- function(input, output) {

    output$mygplot1 <- renderGirafe({

      girafe(ggobj =

               ggplot(

                 api_test, aes(x= value , 
                               y=reorder(cname,value),
                               tooltip=tooltip,
                               data_id=cname)) +
        geom_bar_interactive(
          aes(alpha=.5),
          stat='identity',
          fill = "#56B4E9",
          data= api_test[api_test$variable == input$Variable, ]) +

          labs(
          y = NULL,
          x = "Average",

          caption = paste("Data X: ", api_test[api_test$variable == input$Variable, ]$value),
          title=input$Variable) +

          geom_vline(xintercept = 0, color="black", size=1) +

          scale_x_continuous(
               position = "top",
               labels = scales::number_format(suffix = "%"),
               expand = expand_scale(mult = c(0, 0.05))) +

          theme(
            axis.text.y = element_text(hjust=1),
            plot.title.position = "plot",
            panel.grid.major.y = element_blank(),
            panel.grid.major.x = element_line(size = 1, colour = "grey80"),
            panel.grid.minor.x = element_blank(),
            legend.position = "none",
            text=element_text(family="Georgia",size=12))
        ,
        height_svg=10,
        width_svg =8) %>%

        girafe_options(ggiraph::opts_hover(css="fill:#22222288;cursor:pointer;"))
  })},      
options = list(height = 740))

edo
  • 63
  • 1
  • 4
  • Can you read that chapter?https://davidgohel.github.io/ggiraph/articles/offcran/customizing.html#fonts Font "Georgia" must be available – David Gohel Apr 24 '20 at 15:14
  • Have you tried vjust = ? **theme(axis.text.y = element_text(hjust=1, vjust= *play around with numbers*))** – Ecg Apr 24 '20 at 15:21
  • @DavidGohel if you look at the linked app you will see the font is not changed in that code. I recently saw the same bug, with and without setting any fonts. – Ola Caster Jun 17 '21 at 05:34
  • @OlaCaster link has moved. https://davidgohel.github.io/ggiraph/articles/offcran/fonts.html - I disagree. Setting font help. The example upper don't set font so "Gorgia" must be in the machine running ggiraph and the reader (html side) must have Gorgia on his computer if not added in the CSS – David Gohel Jun 17 '21 at 06:56
  • @DavidGohel I think you misunderstood me. If you go to the OP's linked app at https://eduardo757ag.shinyapps.io/test_labels/ it is still up and running. That code (not the code here on SO) does not alter any fonts, and we still see this label misplacement. – Ola Caster Jun 18 '21 at 07:36
  • 1
    @OlaCaster the issue is explained here: https://davidgohel.github.io/ggiraph/articles/offcran/fonts.html – David Gohel Jun 18 '21 at 09:24

0 Answers0