I am using Plotly to make charts and graphs. Currently I am trying to apply a custom color to my graph, but the graph has more colors than the ColorBrewer palette offers.
Here is my data: https://github.com/kffont/Colorado/blob/master/data1.csv
The data is the min, median and max of 5 number summaries for 15 rows of data. The 16th row identifies the categorical labels (min, med, max).
I used Color Ramp to create a function to allow more colors to be used in my bar plot. That is working fine. The problem occurs when I try and assign the colors to the plot. I've used many solutions to no avail. Here are some of the methods I've tried:
create a vector of colnames, color = colnames colors = color palette
Assign colors with palettename[1] etc using indexing
remove the traces and create 2 lines of code; 1 for the plot and one for the layout. I tried this method with and without the color/colors method in #1
Here is the base code that I've used.
#Libraries
library(plotly)
library(colorRamps)
library(RColorBrewer)
#Create palette col.a.cat1<-colorRampPalette(brewer.pal(9,"YlOrRd"))
#Color = Colnames
abc<-colnames(data1)
#Barcharts #1 (p) and #2 (o)
p<-plot_ly(a.cat.14, x = ~Level, y = ~a.cat.14[, 1],, type = 'bar', name = colnames(a.cat.14[1])) %>%
add_trace(y = ~a.cat.14[, 2], name = colnames(a.cat.14[2])) %>%
add_trace(y = ~a.cat.14[, 3], name = colnames(a.cat.14[3])) %>%
add_trace(y = ~a.cat.14[, 4], name = colnames(a.cat.14[4])) %>%
add_trace(y = ~a.cat.14[, 5], name = colnames(a.cat.14[5])) %>%
add_trace(y = ~a.cat.14[, 6], name = colnames(a.cat.14[6])) %>%
add_trace(y = ~a.cat.14[, 7], name = colnames(a.cat.14[7])) %>%
add_trace(y = ~a.cat.14[, 8], name = colnames(a.cat.14[8])) %>%
add_trace(y = ~a.cat.14[, 9], name = colnames(a.cat.14[9])) %>%
add_trace(y = ~a.cat.14[, 10], name = colnames(a.cat.14[10])) %>%
add_trace(y = ~a.cat.14[, 11], name = colnames(a.cat.14[11])) %>%
add_trace(y = ~a.cat.14[, 12], name = colnames(a.cat.14[12])) %>%
add_trace(y = ~a.cat.14[, 13], name = colnames(a.cat.14[13])) %>%
add_trace(y = ~a.cat.14[, 14], name = colnames(a.cat.14[14])) %>%
add_trace(y = ~a.cat.14[, 15], name = colnames(a.cat.14[15])) %>%
layout(title = "Adult Cats: Minimum, Median, Maximum", yaxis = list(title= 'Count'), barmode = 'group')
p
o<-plot_ly(a.cat.14, x = ~Level, y = ~a.cat.14[, c(1:15)], type = 'bar', name = colnames(a.cat.14)) %>%
layout(title = "Adult Cats: Minimum, Median, Maximum", yaxis = list(title= 'Count'), barmode = 'group')
Your help is appreciated!
