在R中为多行创建散点图

She*_*ila 6 plot r scatter-plot ggplot2 lattice

我有一个看起来像这样的数据框:

        Samp1    Samp2    Samp3     Samp4    Samp5
Gene1    84.1     45.2     34.3      54.6     76.2
Gene2    94.2     12.4     68.0      75.3     24.8
Gene3    29.5     10.5     43.2      39.5     45.5
...
Run Code Online (Sandbox Code Playgroud)

我正在尝试创建一个散点图,其中x轴是样本(Samp1-5),y轴是行(Gene1-3等等),但我希望绘制每行的数据作为同一情节中的不同颜色.

关于如何在R中做到这一点的任何想法?我非常愿意在R中使用ggplot2,格子,汽车或任何其他包装.

Sve*_*ein 1

这是一个解决方案ggplot2

数据:

dat <- read.table(text="Samp1    Samp2    Samp3     Samp4    Samp5
  Gene1    84.1     45.2     34.3      54.6     76.2
  Gene2    94.2     12.4     68.0      75.3     24.8
  Gene3    29.5     10.5     43.2      39.5     45.5", header = TRUE)
Run Code Online (Sandbox Code Playgroud)

剧情:

library(ggplot2)  
ggplot(stack(dat), aes(x = ind, y = values, colour = rownames(dat))) +
  geom_point()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 您好,当我尝试重现您的示例时,为什么会出现此错误?错误:美学必须是长度一,或者与 dataProblems:rownames(dat) 的长度相同 (2认同)