简体   繁体   English

从 ggplotly 图例中删除填充颜色级别

[英]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?有没有办法从ggplotly图例中删除填充颜色,因为它与刻面是多余的? 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.换句话说,我确实有四种组合,但我只想在图例中显示 alpha 的级别,因为分面告诉您与填充值相同的信息。 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 .我不需要解释红色和绿色的含义,因为红色只适用于 facet group3==0而绿色只适用于 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.我从谷歌来到这里是因为当ggplotly()时,给出了一个没有图例的ggplotly()

In case that affects anyone else, the answer is, use:如果影响其他人,答案是,使用:

theme(legend.position='none')

as plotly understands that.正如情节理解的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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