0

I would like to ask you if you could help me in customizing of colors in a donut chart with blue
Initially, i got a blue chart and i extremely to change it to color of green with color code: #90EE90 Can u help me to do that?

enter image description here

library(ggplot2)
library(formattable)
library(lessR)
options(digits=2)
blank_theme <- theme_minimal()+
  theme(
    axis.title.x = element_blank(),
    axis.title.y = element_blank(),
    panel.border = element_blank(),
    panel.grid=element_blank(),
    axis.ticks = element_blank(),
    plot.title=element_text(size=14, face="bold")
  )

dat = data.frame(count=c(21, 80), category=c("Có", "Không" ))


dat$fraction = dat$count / sum(dat$count)

dat$ymax = cumsum(dat$fraction)
dat$ymin = c(0, head(dat$ymax, n=-1))

dat$category <- factor(dat$category, levels = c("Có","Không"))
x <- formattable(dat$fraction, digits = 1, format = "f")

p1 = ggplot(dat, aes(fill=category, ymax=ymax, ymin=ymin, xmax=4, xmin=3)) +
  geom_rect(color='#90EE90') +
  coord_polar(theta="y") +
  xlim(c(1, 4)) 


edu<-p1 +scale_fill_brewer("KCCSBL") + blank_theme + 
  theme(axis.text.x=element_blank()) + theme(legend.position=c(.5, .5)) + ggtitle("") +
  theme(panel.grid=element_blank()) +
  theme(axis.text=element_blank()) +
  theme(axis.ticks=element_blank()) +
  theme(legend.title = element_text(size=13, face="bold")) +
  theme(legend.text = element_text(size = 13)) 

edu1 <- edu +
  geom_label(
    aes(label = paste(x * 100, "%"),
    x = 3.5,
    y = (ymin + ymax) / 2),
    inherit.aes = TRUE,
    show.legend = FALSE
  )

print(edu1)
ggsave('image1.png', edu1, width = 4, height = 3)

i hope someone can teach me how to change to color of #90EE90

stefan
  • 90,330
  • 6
  • 25
  • 51
  • 1
    Welcome to SO! Not 100% clear what you are trying to achieve. If you want custom fill colors then use `scale_fill_manual(values = c("#90EE90", ...))` instead of `scale_fill_brewer`. But as you have two categories you probably want different colors, i.e. you have to provide two colors not just one. For more help please clarify what you are trying to achieve and provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Aug 20 '23 at 18:38
  • 1
    Thanks you so much for your help. How can I rate your comment? – Tran-Huynh Trung Nhu Aug 21 '23 at 12:38
  • Another trouble is that donut show "Category" instead of "KCCSBL"(on of my variable). How i can change from "Category" to "KCCSBL" in the center of my donut chart? Thank you – Tran-Huynh Trung Nhu Aug 21 '23 at 12:43

0 Answers0