如何将条形图添加到 R plotly 条形图?
How to add bar outline to an R plotly bar chart?
我正在创建一个绘图图表,其中包含根据变量类别编码的各个条形图。我在保持条形颜色分类的同时向条形添加黑色轮廓时遇到问题。
下面是我当前的代码。我需要添加什么才能在每个栏上包含黑色轮廓?谢谢。
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)
marker
参数就是你想要的。
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)))
输出:
我正在创建一个绘图图表,其中包含根据变量类别编码的各个条形图。我在保持条形颜色分类的同时向条形添加黑色轮廓时遇到问题。
下面是我当前的代码。我需要添加什么才能在每个栏上包含黑色轮廓?谢谢。
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)
marker
参数就是你想要的。
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)))
输出: