尝试向R ggplot(火山图)添加颜色时出错
想制作一个火山图,根据重要性和差异表达进行着色。使用R中的toptable从Limma对象生成数据帧。根据调整后的p值和logfc向数据框添加颜色列。所以每个基因也有一个指定的颜色(“填充”),然后用这些颜色来绘制ggplot:尝试向R ggplot(火山图)添加颜色时出错,r,ggplot2,limma,R,Ggplot2,Limma,想制作一个火山图,根据重要性和差异表达进行着色。使用R中的toptable从Limma对象生成数据帧。根据调整后的p值和logfc向数据框添加颜色列。所以每个基因也有一个指定的颜色(“填充”),然后用这些颜色来绘制ggplot: geom_point(mapping = aes(x= logFC, y= log10adj, colour = fill))+ geom_hline(yintercept=1.3, linetype="dashed", color = "red")+ geom_
geom_point(mapping = aes(x= logFC, y= log10adj, colour = fill))+
geom_hline(yintercept=1.3, linetype="dashed", color = "red")+
geom_vline(xintercept=-1, linetype="dashed", colour= "blue")+
geom_vline(xintercept=1, linetype="dashed", colour= "blue")+
xlab("Log2 Fold Change")+
ylab("-Log10 Adjusted P-value")+
xlim(-3,3)+
theme_grey()
但是,ggplot的颜色不正确:
如果我将形状添加到美学中,我会得到一个错误:
ggplot(voom_topt)+
geom_point(mapping = aes(x= logFC, y= log10adj, colour = fill, shape = 23))+
geom_hline(yintercept=1.3, linetype="dashed", color = "red")+
geom_vline(xintercept=-1, linetype="dashed", colour= "blue")+
geom_vline(xintercept=1, linetype="dashed", colour= "blue")+
xlab("Log2 Fold Change")+
ylab("-Log10 Adjusted P-value")+
xlim(-3,3)+
theme_grey()
错误:连续变量无法映射到形状
运行rlang::last_error()
查看错误发生的位置
有人知道如何解决这个问题吗?我不明白为什么会出问题(Ps我对R很陌生)
谢谢您的帮助!!您需要使用
scale\u color\u手册
ggplot(mtcars) +
geom_point(mapping = aes(
x = mpg, y = wt, color = factor(cyl))) +
scale_color_manual(values = c("red", "black", "green"))
根据我对代码的了解,您可以设置color=factor(fill)
然后将四种颜色传递到scale\u color\u手册