Reputation:
Wanted to make a volcano plot that was coloured based on signifcance and differential expression. Made a dataframe using toptable in R from Limma object. Added colour column to to the data frame based on adjusted p value and logfc. So each gene also had a colour assigned ("fill), then used these colours to make ggplot:
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()
But then the ggplot isn't coloured properly:
If i add shape to the aesthetic i get an error:
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()
Error: A continuous variable can not be mapped to shape Run
rlang::last_error()
to see where the error occurred.
Does anyone have any idea how to resolve this? I cant figure out why this is going wrong (Ps i am quite new to R)
Thanks for any help!!
Upvotes: 0
Views: 398
Reputation: 4169
You need to use scale_color_manual
as so
ggplot(mtcars) +
geom_point(mapping = aes(
x = mpg, y = wt, color = factor(cyl))) +
scale_color_manual(values = c("red", "black", "green"))
From what I can see with your code, you would set color = factor(fill)
then pass your four colors to the scale_color_manual
Upvotes: 1