简体   繁体   English

绘制 R 中的行与列

[英]Plotting Rows vs Columns in R

Say I have a dataframe where the rows correspond to samples and each column corresponds to how often some molecule appears in the sample.假设我有一个 dataframe,其中行对应于样本,每列对应于样本中某些分子出现的频率。 How do I create a plot so that each molecule name is on the x axis and how often it appears in each sample on the y axis.我如何创建一个 plot,以便每个分子名称位于 x 轴上,并且它在每个样本中出现的频率位于 y 轴上。

For example:例如:

temp <- data.frame(mol1 = c(0.2,0.3,0.5), 
                   mol2 = c(0.4,0.7,0.3), 
                   mol3 = c(0.1, 0, 0.8))
rownames(temp) <- c("S1", "S2", "S3")

There would be a tick for "mol1" on the x-axis with the values 0.2, 0.3, and 0.5 above it labeled or with a legend.在 x 轴上会有一个“mol1”的勾号,上面标有 0.2、0.3 和 0.5 的值或带有图例。 The same for the other molecules.其他分子也一样。

Perhaps you can try to plot with ggplot :也许你可以尝试 plot 与ggplot

library(tidyverse)

temp %>%
  rownames_to_column('sample') %>%
  pivot_longer(cols = -sample, names_to = 'molecule') %>%
  ggplot() + aes(sample, value, color = molecule) + 
 geom_point(size = 3) + theme_bw()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM