简体   繁体   中英

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. 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.

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. The same for the other molecules.

Perhaps you can try to plot with 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()

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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