0
votes

Take the following "Horizontal grid" example from the Plotly ggplot2 Library

I want to omit the labels from the X axes in both subplots, like:

The way to do this should be, allegedly, by using the layout() function and including configuration parameter xaxis = list(showticklabels = FALSE). See however the output in the following reprex:

library(tidyverse)
library(reshape2)
library(plotly)

p <- ggplot(tips, aes(x=total_bill, y=tip/total_bill)) + geom_point(shape=1) +
  facet_grid(. ~ sex)

ggplotly(p) %>%
  layout(xaxis = list(showticklabels = FALSE))

As you can see, only the first subplot is affected.

I have already tried by rendering each subplot as a plotly object, and then using the subplot function:

tips %>% group_split(sex) %>% map(
  ~{
    p <- ggplot(., aes(x=total_bill, y=tip/total_bill)) + geom_point(shape=1)
    ggplotly(p)
  }
) %>%
  subplot(shareY = TRUE) %>%
  layout(xaxis = list(showticklabels = FALSE))

The result is the same.

Also, calling layout(., xaxis = list(showticklabels = FALSE)) for each subplot individually fails, as subplot() apparently overrides the layout of the subplots.

Additionally, inspection of the JSON object seems to show that only one layout attribute is generated for the whole subplot, which I understand should control the properties of all subplots.

Any idea on how to solve this? Any help would be much appreciated!

1

1 Answers

1
votes

To achieve what you desire, removing all x-axis labels from the ticks, I would remove them using your ggplot theme. Thus before you call ggplotly

p <- ggplot(tips, aes(x=total_bill, y=tip/total_bill)) +
        geom_point(shape=1) +
        facet_grid(. ~ sex) + 
        theme( axis.text.x=element_blank()) # remove x-labels
p 

ggplotly(p)