简体   繁体   中英

remove fill color levels from a ggplotly legend

Is there a way to remove the fill color from the ggplotly legend since it is redundant with the facet? In other words, it's true that I essentially have four combinations, but I only want to show the levels of alpha in the legend because the faceting tells you the same information as the fill values. I don't need to explain what red and green mean since red only applies to facet group3==0 and green only applies to facet group3==1 .

在此处输入图片说明

---
title: "Example"
runtime: shiny
output:
  flexdashboard::flex_dashboard:
    vertical_layout: fill
---

```{r}
  library(tidyverse)
  library(plotly)
  library(flexdashboard)
```


### Chart 1

```{r}
  f <- list(family = "Poppins")
  a <- list(tickfont = f)

  p <- fortify(forecast::gold) %>%
       mutate(group1 = sample(0:1, n(), replace=TRUE),
              group2 = sample(0:1, n(), replace=TRUE),
              group3 = sample(0:1, n(), replace=TRUE)
              ) %>%
    ggplot(., aes(factor(group1), y, alpha=factor(group2), fill=factor(group3))) + 
         geom_col() + 
         scale_alpha_manual(values = c(.5, 1)) +
         facet_wrap(~group3)

  ggplotly(p)
```

I arrived here from google because a ggplot that didn't have a legend was being given one when ggplotly() was called on it.

In case that affects anyone else, the answer is, use:

theme(legend.position='none')

as plotly understands that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM