如何将条形轮廓添加到r Plotly bar图表中?

发布于 2025-01-29 12:10:28 字数 514 浏览 4 评论 0原文

我正在创建一个基于变量类别编码的单个条形图的情节图表。我在将棒的颜色分类的同时,在钢筋上添加黑色轮廓很难。

以下是我当前的代码。我需要添加什么才能在每个栏上包含一个黑色轮廓?谢谢。

library(plotly)
library(tidyverse) 

my_tibble <- tibble(mins = runif(10,10,30),
                     week = 1:10,
                     exercise = c("a", "b", "b", "b", "a", "a", "b", "b", "b", "a"))

example_hex <- c('#70AD47', '#404040', '#CAE1F1', '#24608B')

plot_ly(
  data = my_tibble,
  type = 'bar',
  x = ~week,
  y = ~mins,
  color = ~exercise,
  colors = example_hex)

I am creating a plotly chart with individual bars coded based on a variable category. I am having trouble adding a black outline to the bars while keeping the bars' color categorization.

Below is my current code. What do I need to add to include a black outline on each bar? Thank you.

library(plotly)
library(tidyverse) 

my_tibble <- tibble(mins = runif(10,10,30),
                     week = 1:10,
                     exercise = c("a", "b", "b", "b", "a", "a", "b", "b", "b", "a"))

example_hex <- c('#70AD47', '#404040', '#CAE1F1', '#24608B')

plot_ly(
  data = my_tibble,
  type = 'bar',
  x = ~week,
  y = ~mins,
  color = ~exercise,
  colors = example_hex)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深爱成瘾 2025-02-05 12:10:28

标记参数是您所追求的。

library(plotly)
library(tidyverse) 

my_tibble <- tibble(mins = runif(10,10,30),
                    week = 1:10,
                    exercise = c("a", "b", "b", "b", "a", "a", "b", "b", "b", "a"))

example_hex <- c('#70AD47', '#404040', '#CAE1F1', '#24608B')

plot_ly(data = my_tibble) %>% 
  add_trace(
    type = 'bar',
    x = ~week,
    y = ~mins,
    color = ~exercise,
    marker = list(line = list(color = "black", width = 5)))

输出:

“

The marker parameter is what you are after.

library(plotly)
library(tidyverse) 

my_tibble <- tibble(mins = runif(10,10,30),
                    week = 1:10,
                    exercise = c("a", "b", "b", "b", "a", "a", "b", "b", "b", "a"))

example_hex <- c('#70AD47', '#404040', '#CAE1F1', '#24608B')

plot_ly(data = my_tibble) %>% 
  add_trace(
    type = 'bar',
    x = ~week,
    y = ~mins,
    color = ~exercise,
    marker = list(line = list(color = "black", width = 5)))

Output:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文