更改geom_text的文本颜色

时间:2018-05-15 16:32:20

标签: r ggplot2

我想改变情节中所有文字的颜色。我有代码,但我的文字颜色不是白色。如何更改白色的文字颜色?

数据

dput(tt)
structure(list(STREAM = c("Applications", "BI", "CRE & Telecom & Scoring", 
"FACE & Antifraud", "IFRS9 & Provision", "Portfolio & Production", 
"Техдолг", "Операционка"), PLANS = c(61, 2, 2, 23, 13, 29, 12, 
16), DONE = c(0.8, 0.5, 0.85, 0.65, 0.95, 0.45, 0.9, 0.3)), .Names = c("STREAM", 
"PLANS", "DONE"), row.names = c(NA, -8L), class = c("tbl_df", 
"tbl", "data.frame"))

代码

library(ggplot2)

library(dplyr)
tt$n=tt$PLANS
tt$sp=tt$DONE
tt$perc=paste(round(tt$sp * 100, 1), "%", sep="")
# Make the plot

tt$max_sp=1
tt$pos <- 0.5 * (cumsum(tt$n) + cumsum(c(0, tt$n[-length(tt$n)])))
pos=tt$pos
# Colour pallet
#cbbPalette <-c("#94C2DA", "#707070", "#DCBFAD", "#707070", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
cbbPalette <-c("#ac7070", "#d39c3f", "#654982", "#4a6785", "#8eb021", "#f15c75", "#815b3a", "#7f7f7f")
#Create chart
p=ggplot(data = tt) + 
  geom_bar(aes(x = pos, width = n, y = sp, fill = `STREAM`), stat = "identity") + 
  geom_text(aes(x = pos, width = n, y = sp, label = perc,color="white"), vjust=0, position = position_stack(vjust = 0.5), size = 7)  +
  scale_x_continuous(labels = tt$`STREAM`, breaks = pos)+
  scale_fill_manual(values=cbbPalette)+
  geom_bar(aes(x = pos, width = n, y = max_sp, fill = `STREAM`), stat = "identity",alpha = 0.6) +
  ylim(-1,1)+

  theme_minimal() +  theme(
    axis.text = element_blank(),
    axis.title = element_blank(),
    panel.grid = element_blank(),
    legend.position="none" 

  )+coord_polar(start = 0) 
p

结果 enter image description here

0 个答案:

没有答案