I have a function to generate plots that includes labels for some of the points. When I run the code outside of a function call everything looks good, but when I return the plot from the function and then display it the labels are gone.
myFun <- function(data){
...
diff.out, numDiff produced from data input
...
p1 <- ggplot(diff.out, aes(x = log2FoldChange, y = -log10(padj), label = text.label)) + geom_point(aes(color = factor(point.color))) + scale_color_manual(labels = labs,values = colors ) + geom_text_repel(aes(label = diff.out$text.label), nudge_y = 0.01, size = 3) + labs(color =(paste0("Diff. Exp. Genes (", sum(numDiff[c("down", "up")]), ")")))
return(p1)
}
Running the plotting code gives plot with labels
p1 <- ggplot(......)
print(p1)
#Running the function and returning the plot gives plot without labels
myPlot <- myFun(data)
print(myPlot)
Any advice would be greatly appreciated! I am new to ggplot2...