Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

question from:https://stackoverflow.com/questions/65713088/plotting-rows-vs-columns-in-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
736 views
Welcome To Ask or Share your Answers For Others

1 Answer

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()

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...