Skip to content

ggplotly() doesn't support multiple colors in axis ticks #1328

Open
@nicocriscuolo

Description

@nicocriscuolo

Hello and thanks for the great job you did by making this really useful package. I just want to report an issue that appears when I need to colour the axis text of a plot with pre - defined colours. Below you can see the R code to build a really simple shiny app. If I plot my graph with the standard ggplot() function the names of the x axis result colored, but if I use the function ggplotly() to make my plot interactive, the text of the x axis remains black (the functions recognizes the arguments "angle" and "hjust" but not "col").

Thanks in advance for the availability.

Nico

library(ggplot2)
library(plotly)
library(shiny)

### UI
ui <- fluidPage(
  fluidRow(
    column(width = 8,
           plotlyOutput(outputId = "plot", 
                        height = "600px"))))

### SERVER
server <- function(input, output) {
  
output$plot <- renderPlotly({
  
  mpg_s <- mpg[c(1, 19, 38), ] # subset to pick just 3 rows
  
  col <- c("red", "green", "blue")
  
  p <- ggplot(data = mpg_s,
              aes(x = manufacturer, y = hwy)) +
         geom_point() +
         theme(axis.text.x = element_text(size = 20,
                                         angle = 90,
                                         hjust = 1,
                                         colour = col))
  
  ggplotly(p)

  })
}

### LUNCH APP
shinyApp(ui = ui, server = server)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions