GuangchuangYu/yyplot

给axis.text分组上色

brightbio opened this issue · 0 comments

余教授:
您好!
我想要实现与下面类似的图,用变量给axis text.x上色,
nvsc_go_enrichment
也就是说:怎么将条形图中 “y轴标签颜色” 改为“对应条形的填充色”?
数据和脚本如下:
test data.txt

`library(ggplot2)

library(reshape2)
windowsFonts(myFont = windowsFont("Times New Roman"))
data<-read.table('clipboard',header = T,sep='\t' )
head(data)
#按输入顺序输出
levels.x <- data$Description
p<-ggplot(data, aes(x= Description, y= Count, fill= Ontology))+
scale_fill_manual("Ontology", values = c("BP" = "red", "CC" = "black","MF"="blue"))+
geom_bar(stat="identity", width= 0.8)+
scale_x_discrete(limits=levels.x, position = "top")+
labs(x="GO terms",y="Gene number")+
ylim(20,0)+
theme_grey()+
theme(legend.position = c(0.2,0.9), legend.direction="vertical",
legend.key.size=unit(6,'mm'),
#legend.box.background=element_rect(fill= "green", color="green"),
axis.title.x=element_text(size=13, family="myFont", color = "black", face = "bold"),
axis.title.y=element_text(size=13,family="myFont", color = "black", face = "bold"),
axis.text.x=element_text(size=9, colour="black", face = "bold"),
axis.text.y=element_text(size=9, colour="black", face = "plain"))+
coord_flip()
require(yyplot)
cols <- c(BP = "red", CC = "black", MF="blue")
p2 <- set_axis_text_color(p, colors=cols, mapping=~Ontology, fake_aes='color', axis="x")`
但是出现以下错误:
lfeu l0i5wjxds 0dkzrhw2
烦请余教授点拨一二,谢谢!
祝好