简体   繁体   中英

How to plot profiles in R with ggplot2

I have a large data set with protein IDs and corresponding abundance profiles across a number of gel fractions. I want to plot these profiles of abundances across the fractions.

The data looks like this

IDs<- c("prot1", "prot2", "prot3", "prot4")
fraction1 <- c(3,4,2,4)
fraction2<- c(1,2,4,1)
fraction3<- c(6,4,6,2)
plotdata<-data.frame(IDs, fraction1, fraction2, fraction3)

> plotdata
    IDs  fraction1  fraction2  fraction3
1 prot1          3          1          6
2 prot2          4          2          4
3 prot3          2          4          6
4 prot4          4          1          2

I want it to look like this: 出众的蛋白质丰度图

Every protein has a profile. Every fraction has a corresponding abundance value per protein. I want to have multiple proteins per plot.

I tried figuring out ggplot2 using the cheat sheet and failed. I don't know what the input df should look like and what method I should use to get these profiles.

I would use excel, but a bug draws the wrong profile of my data depending on order of data, so I can't trust it to do what I want.

First, you'll have to reorganize your data.frame for ggplot2. You can do it one step with reshape2::melt . Here you can change the 'variable' and 'value' names.

library(reshape2)
library(dplyr)
library(ggplot2)
data2 <- melt(plotdata, id.vars = "IDs")

Then, we'll group the data by protein:

data2 <- group_by(data2, IDs)

Finally, you can plot it quite simply:

ggplot(data2) +
    geom_line(aes(variable, value, group = IDs,
                  color = IDs))

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