IRT
IRT

Reputation: 209

Pie chart custom color palette percent

I have to use a color palette given by my organisation. But I have errors message.

DT <- data.table(induse = c("C29", "P7","TOTAL"), values = c(570,100,600))
paletteEcoFin <- c("9A5EA6", "E5C473", "B98B50", "61276D", "2E368F","D8C5E0", "0000FF", "800080")
pie = ggplot(DT, aes(x="", y=values, fill=induse)) + geom_bar(stat="identity", width=1)
pie = pie + coord_polar("y", start=0) 
+  scale_fill_manual(values=paletteEcoFin) 

Error when I try to view pie is

  Error in grDevices::col2rgb(colour, TRUE) : invalid color name 'B98B50'

Furthermore, how can I get automatic % calculated and showed on the pie chart? Thanks.

Upvotes: 0

Views: 1209

Answers (1)

Ulises Rosas-Puchuri
Ulises Rosas-Puchuri

Reputation: 1970

Please consider to change first three values of paletteEcoFin vector (i.e. adding #, as a regular hexcolor):

paletteEcoFin <- c("#9A5EA6", "#E5C473", "#B98B50", "61276D", "2E368F","D8C5E0", "0000FF", "800080")

ggplot(DT, aes(x="", y=values, fill=induse)) + 
  geom_bar(stat="identity", width=1) +
  coord_polar("y", start=0) + 
  scale_fill_manual(values=paletteEcoFin)

enter image description here

Upvotes: 2

Related Questions