ggplot2做图(填坑中)

数据

df <- data.frame(x = 1:10, y = 1:10, f = c(rep("A", 5), rep("B", 5)))

ggplot2做图(填坑中)_第1张图片ggplot2做图(填坑中)_第2张图片

做图

1. 散点图 (scatter plot)

# scatter plot
scatter_plot <- function(df, metadata) {
  identical(rownames(df), rownames(metadata))
  data <- cbind(df, metadata)
  cor_res <- cor(data$x, data$y, method = "spearman")
  x <- unlist(data$x)
  y <- unlist(data$y)
  plot(x, y, pch = 19, xlab = "X", ylab = "Y") +
    abline(lm(x ~ y), col = "purple", lwd = 3) + # Regression line
    text(0.4 * max(data$x), 0.8 * max(data$y), paste("Correlation:", round(cor_res, 2))) # Pearson correlation
}

scatter_plot(df, metadata)

ggplot2做图(填坑中)_第3张图片

2. 柱状图 (bar plot)

3. 堆积柱状图 (stacked bar chart)

4. 热图 (heatmap)

代码

你可能感兴趣的:(生信,信息可视化,ggplot2,R,做图,生物信息学)