0

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.

IRT
  • 209
  • 2
  • 11
  • 1
    You forgot to add the ‘#’ in front of the hex codes. For the % labels, see this answer: https://stackoverflow.com/questions/41338757/adding-percentage-labels-on-pie-chart-in-r – Jelle Feb 16 '19 at 14:58

1 Answers1

2

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

Ulises Rosas-Puchuri
  • 1,900
  • 10
  • 12
  • It answers the first part of the question.Thanks for this. But for the second part, how to represent in the graph the % and not the values, like 570/870 in %, 100/870 and 200/870 in % ? – IRT Feb 19 '19 at 10:42