plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

ggplotly: problems with facet_grid/axes

Open alyst opened this issue 6 years ago • 2 comments

I'm trying to display some block-matrix-like plot, and there are a few regressions when converting from ggplot to ggplotly conversion (ranked by severity):

  • degenerated (1 value) discrete axes are implicitly converted into continuous numeric axis centered around 1, original labels not displayed
  • switch="both" and strip.placement = "outside" options ignored (here it's important because with ggplot I am able to have sort-of 2-level hierarchy for X and Y axes, which ggplotly breaks)
  • some subplots with missing data are displayed (at 3x3 position), some don't (2x2 position)
  • the margins for the X labels are too small (is the text rotation considered when calculating the necessary space?)
  • space="free" option ignored
  • within my shiny application the diagonal subplots miss the fill color. It's an important issue, but I cannot make a small reproducible example (screenshot attached).

ggplot2 capza1_ggplot_render

ggplotly capza1_plotly_render

ggplotly from Shiny app capza1_plotly_shiny_render

The code

require(readr)
require(plotly)
require(ggplot2)

peakXpepmod.df <-  read_tsv("CAPZA1_example.txt",
                            col_types = list("pepmod_id"="c", "peak_id"="c", "proteoform_id"="c", "pmgroup_id"="c")) %>%
  dplyr::mutate(pepmod_id = factor(pepmod_id),
                peak_id = factor(peak_id),
                proteoform_id = factor(proteoform_id),
                pmgroup_id = factor(pmgroup_id))

p <- ggplot(peakXpepmod.df) +
  geom_point(aes(x = pepmod_id, y = peak_id,
                 color = proteoform_id), shape=15, size=8) +
  geom_point(aes(x = pepmod_id, y = peak_id,
                 shape = pmgroup_id), size=5) +
  scale_x_discrete("Pepmods") + scale_y_discrete("Peaks") +
  theme( axis.line = element_line(colour = "gray80"),
         axis.ticks = element_line(colour = "gray80"),
         axis.text.x = element_text(angle = 90, hjust = 1),
        strip.background = element_rect(colour="gray"),
        strip.placement = "outside") +
  facet_grid(proteoform_id ~ pmgroup_id, switch="both", scales = "free", space = "free")

# ggplot
p

# ggplotly
ggplotly(p)

The dataset CAPZA1_example.txt

alyst avatar Jul 27 '17 13:07 alyst