Skip to content

Instantly share code, notes, and snippets.

@jasper1918
Created August 15, 2017 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasper1918/36db5617bc238ace80268971c5b3e6eb to your computer and use it in GitHub Desktop.
Save jasper1918/36db5617bc238ace80268971c5b3e6eb to your computer and use it in GitHub Desktop.
fc plot
plot_fc<-function(df, key1_x, key1_y, key2_x, key2_y, plot_xlab="", plot_ylab=""){
l1x<-log2(df[,key1_x] +1)
l1y<-log2(df[,key1_y] +1)
l2x<-log2(df[,key2_x] +1)
l2y<-log2(df[,key2_y] +1)
diff1 <- l1x - l1y
diff2 <- l2x - l2y
names(diff1) <- "DIFF1"
names(diff2) <- "DIFF2"
df <- data.frame("DIFF1"=diff1, "DIFF2"=diff2, check.names = F)
max_val<-ceiling(max(abs(max(df$DIFF1)),abs(max(df$DIFF2))))
min_val<-floor(min(df$DIFF1, df$DIFF2))
seq_val<-round(seq(min_val, max_val, by = 1),1)
all <- ggplot(df, aes(DIFF1, DIFF2)) +
geom_point(size=2, color="black", alpha=.5, shape=17) +
geom_abline(slope =1, intercept=0, color="red") +
geom_smooth(colour = "blue", method='loess', alpha=.2, se=F) +
geom_smooth(colour = "green2", method='lm', alpha=.2, se=F) +
# scale_x_continuous(seq_val) +
# scale_y_continuous(seq_val) +
expand_limits(y=c(min_val, max_val), x=c(min_val, max_val)) +
labs(x=plot_xlab, y=plot_ylab) +
theme_bw() +
theme(text = element_text(size=14)) +
theme(legend.position="none")
final_plot <- all + geom_text(x=max_val/3,y=min_val,
label = lm_eqn(df, "DIFF2", "DIFF1"),size=5, parse = TRUE)
return(final_plot)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment