Hi, I want to use plotly to display different shades of red depending on the category column.
grp <- c(“A”, “B”, “C”, “D”)
xval <- as.factor(c(‘x’, ‘y’, ‘x’, ‘y’))
frame <- merge(grp, xval, all=T)
yval <- as.factor(c(‘low’, ‘low-medium’, ‘medim-high’, ‘high’))
df <- tbl_df(cbind(frame, yval))
colnames(df) <- c(“category”, “Type”, “Range”)
df %>% group_by(category) %>% arrange(Type) %>%
plot_ly( x = ~Type, y = ~Range, color= ~category, type = ‘bar’
)%>%
layout(yaxis = list(title = ‘value’), barmode = ‘stack’)
below is the result:
How can I change the color to be a range of red? I tried to define the colors i wanted:
colors <- c( ‘rgb(252,174,145)’, ‘rgb(251,106,74)’, ‘rgb(222,45,38)’, ‘rgb(165,15,21)’)
But it didn’t work.
Can anyone help please? I want to the colors for each bar to be like this: