Creation of ridgeline plot from HPLC chromatogram data

Hi,

I have been trying to generate a ridgeline plot based on some data from my recent experiment.
I ran several samples and want to generate a graphic in order to compare them. They are HPLC analysis and a ridgeline plot is probably the best approach to compare them.

I would like to create something similar to this graphic

When I create the plot, I obtain a similar profile for all the sample which makes no sense.

Here is my code:

> library(readxl)
> HPLC_Data <- read_excel("Desktop/R-studio presentation/Catalase inhibitor SA.xls", 
+     sheet = "Formated", range = "A1:F49")
> View(HPLC_Data)                                                                                                             
> library(ggplot2)
> library(ggridges)
> library(tidyr)
> library(reprex)
> library(datapasta)
> dim(HPLC_Data)
[1] 48  6
> gather(HPLC_Data, Sample, Absorbance, 2:6)
# A tibble: 240 x 3
    Time Sample      Absorbance
   <dbl> <chr>            <dbl>
 1  3.09 Control 16H       2965
 2  3.10 Control 16H       2830
 3  3.10 Control 16H       2624
 4  3.11 Control 16H       2763
 5  3.12 Control 16H       3126
 6  3.12 Control 16H       2947
 7  3.13 Control 16H       3046
 8  3.13 Control 16H       2845
 9  3.14 Control 16H       3039
10  3.15 Control 16H       2472
# … with 230 more rows
> HPLC_Data_Long <- gather(HPLC_Data, Sample, Absorbance, 2:6)
> ggplot(HPLC_Data_Long, aes(x = Time, y = Sample)) + geom_density_ridges()
Picking joint bandwidth of 0.0345
> reprex::reprex()
Removing leading prompts from reprex source.
Rendering reprex...
Error: callr subprocess failed: <text>:20:13: unexpected '='
19: HPLC_Data <- read_excel("Desktop/R-studio presentation/Catalase inhibitor SA.xls", 
20: +     sheet =

And here is the graph generated, all profiles are similar but they should be different

I cannot understand, which information/command is missing.

Or do I need to mention "Absorbance" as y and group my samples?

Here is a sample data set:
After generating this data sample, I notice my values are followed with a "L", e.g. "2054L", is it the reason why I cannot generate a correct plot?

HPLC_Data <- tibble::tribble(
               ~Time, ~Control.16H, ~`0.05mM.16H`, ~`0.1mM.16H`, ~`0.5mM.16H`, ~`1mM.16H`, ~`5.mM.16H`,
               3.093,        2965L,         1409L,        2054L,        1380L,      1795L,       1135L,
               3.099,        2830L,         1584L,        2278L,        1386L,      2232L,       1411L,
               3.105,        2624L,         1574L,        2209L,        1232L,      1771L,       1331L,
               3.111,        2763L,         1460L,        2294L,        1348L,      1969L,       1035L,
               3.117,        3126L,         1467L,        2342L,        1386L,      1615L,       1370L,
               3.123,        2947L,         1568L,        2354L,        1383L,      1924L,       1336L,
               3.129,        3046L,         1533L,        2108L,        1327L,      1787L,       1364L,
               3.134,        2845L,         1625L,        2371L,        1321L,      1674L,       1287L,
                3.14,        3039L,         1615L,        2315L,        1293L,      2197L,       1276L,
               3.146,        2472L,         1621L,        2310L,        1137L,      1891L,       1034L,
               3.152,        2654L,         1304L,        2292L,        1491L,      1703L,       1136L,
               3.158,        2489L,         1492L,        2249L,        1302L,      1689L,       1413L,
               3.164,        2788L,         1482L,        2358L,        1388L,      1864L,       1376L,
                3.17,        2745L,         1625L,        2239L,        1290L,      1804L,       1043L,
               3.176,        2769L,         1477L,        2231L,        1125L,      2304L,       1296L,
               3.182,        2813L,         1655L,        2516L,        1384L,      1909L,       1251L,
               3.188,        2648L,         1388L,        2185L,        1330L,      1926L,       1420L,
               3.194,        2900L,         1383L,        2189L,         838L,      1894L,       1213L,
                 3.2,        3242L,         1465L,        2310L,        1280L,      1600L,       1372L,
               3.206,        2949L,         1675L,        2079L,        1212L,      1970L,       1329L,
               3.212,        2644L,         1354L,        2282L,        1290L,      2169L,       1239L,
               3.218,        2951L,         1302L,        2722L,        1146L,      1771L,       1390L,
               3.223,        2637L,         1442L,        2011L,        1154L,      1603L,       1116L,
               3.229,        2688L,         1398L,        2540L,        1289L,      1925L,       1330L,
               3.235,        3140L,         1466L,        2329L,        1465L,      1712L,       1337L,
               3.241,        3341L,         1151L,        2084L,        1431L,      1669L,       1288L,
               3.247,        2843L,         1406L,        2116L,        1317L,      1618L,       1265L,
               3.253,        2287L,         1693L,        2514L,        1210L,      1762L,       1192L,
               3.259,        2312L,         1343L,        2014L,         968L,      1552L,       1237L,
               3.265,        2266L,         1315L,        1662L,        1056L,      1550L,       1018L,
               3.271,        1775L,         1067L,        1380L,         769L,      1015L,        657L,
               3.277,        1276L,          709L,        1210L,         582L,       956L,        509L,
               3.283,        1202L,          688L,         903L,         221L,       456L,        303L,
               3.289,        1010L,          206L,         653L,         194L,       348L,        309L,
               3.295,         576L,          184L,         544L,         236L,       257L,          0L,
               3.301,         517L,            0L,         327L,         183L,       164L,          0L,
               3.307,         485L,          187L,         348L,         161L,       306L,        272L,
               3.313,         615L,          188L,         381L,         212L,       247L,        234L,
               3.318,         461L,          244L,         360L,         202L,       268L,        282L,
               3.324,         549L,          217L,         481L,         203L,       182L,        280L,
                3.33,         537L,            0L,         387L,         214L,       292L,        211L,
               3.336,         354L,          235L,         328L,         250L,       245L,        243L,
               3.342,         344L,          233L,         335L,           0L,       257L,        218L,
               3.348,         473L,            0L,         437L,           0L,       281L,        213L,
               3.354,         474L,            0L,         228L,         200L,       311L,        193L,
                3.36,         414L,          274L,         370L,         229L,       205L,        202L,
               3.366,         335L,          185L,         285L,         207L,       316L,        277L,
               3.372,         507L,          161L,         321L,         226L,       327L,        172L,
               3.378,         285L,          236L,         498L,         259L,       383L,        173L,
               3.384,         477L,          202L,         179L,         241L,       253L,        210L,
                3.39,         336L,            0L,         251L,         191L,         0L,        167L
               )
head(HPLC_Data)
#> # A tibble: 6 x 7
#>    Time Control.16H `0.05mM.16H` `0.1mM.16H` `0.5mM.16H` `1mM.16H` `5.mM.16H`
#>   <dbl>       <int>        <int>       <int>       <int>     <int>      <int>
#> 1  3.09        2965         1409        2054        1380      1795       1135
#> 2  3.10        2830         1584        2278        1386      2232       1411
#> 3  3.10        2624         1574        2209        1232      1771       1331
#> 4  3.11        2763         1460        2294        1348      1969       1035
#> 5  3.12        3126         1467        2342        1386      1615       1370
#> 6  3.12        2947         1568        2354        1383      1924       1336

Thank you for your help.

Hi @fgaascht,
Thanks for posting your data and code - it has made it easy to find a solution.
Try this:

HPLC_Data <- tibble::tribble(
               ~Time, ~Control.16H, ~`0.05mM.16H`, ~`0.1mM.16H`, ~`0.5mM.16H`, ~`1mM.16H`, ~`5.mM.16H`,
               3.093,        2965L,         1409L,        2054L,        1380L,      1795L,       1135L,
               3.099,        2830L,         1584L,        2278L,        1386L,      2232L,       1411L,
               3.105,        2624L,         1574L,        2209L,        1232L,      1771L,       1331L,
               3.111,        2763L,         1460L,        2294L,        1348L,      1969L,       1035L,
               3.117,        3126L,         1467L,        2342L,        1386L,      1615L,       1370L,
               3.123,        2947L,         1568L,        2354L,        1383L,      1924L,       1336L,
               3.129,        3046L,         1533L,        2108L,        1327L,      1787L,       1364L,
               3.134,        2845L,         1625L,        2371L,        1321L,      1674L,       1287L,
                3.14,        3039L,         1615L,        2315L,        1293L,      2197L,       1276L,
               3.146,        2472L,         1621L,        2310L,        1137L,      1891L,       1034L,
               3.152,        2654L,         1304L,        2292L,        1491L,      1703L,       1136L,
               3.158,        2489L,         1492L,        2249L,        1302L,      1689L,       1413L,
               3.164,        2788L,         1482L,        2358L,        1388L,      1864L,       1376L,
                3.17,        2745L,         1625L,        2239L,        1290L,      1804L,       1043L,
               3.176,        2769L,         1477L,        2231L,        1125L,      2304L,       1296L,
               3.182,        2813L,         1655L,        2516L,        1384L,      1909L,       1251L,
               3.188,        2648L,         1388L,        2185L,        1330L,      1926L,       1420L,
               3.194,        2900L,         1383L,        2189L,         838L,      1894L,       1213L,
                 3.2,        3242L,         1465L,        2310L,        1280L,      1600L,       1372L,
               3.206,        2949L,         1675L,        2079L,        1212L,      1970L,       1329L,
               3.212,        2644L,         1354L,        2282L,        1290L,      2169L,       1239L,
               3.218,        2951L,         1302L,        2722L,        1146L,      1771L,       1390L,
               3.223,        2637L,         1442L,        2011L,        1154L,      1603L,       1116L,
               3.229,        2688L,         1398L,        2540L,        1289L,      1925L,       1330L,
               3.235,        3140L,         1466L,        2329L,        1465L,      1712L,       1337L,
               3.241,        3341L,         1151L,        2084L,        1431L,      1669L,       1288L,
               3.247,        2843L,         1406L,        2116L,        1317L,      1618L,       1265L,
               3.253,        2287L,         1693L,        2514L,        1210L,      1762L,       1192L,
               3.259,        2312L,         1343L,        2014L,         968L,      1552L,       1237L,
               3.265,        2266L,         1315L,        1662L,        1056L,      1550L,       1018L,
               3.271,        1775L,         1067L,        1380L,         769L,      1015L,        657L,
               3.277,        1276L,          709L,        1210L,         582L,       956L,        509L,
               3.283,        1202L,          688L,         903L,         221L,       456L,        303L,
               3.289,        1010L,          206L,         653L,         194L,       348L,        309L,
               3.295,         576L,          184L,         544L,         236L,       257L,          0L,
               3.301,         517L,            0L,         327L,         183L,       164L,          0L,
               3.307,         485L,          187L,         348L,         161L,       306L,        272L,
               3.313,         615L,          188L,         381L,         212L,       247L,        234L,
               3.318,         461L,          244L,         360L,         202L,       268L,        282L,
               3.324,         549L,          217L,         481L,         203L,       182L,        280L,
                3.33,         537L,            0L,         387L,         214L,       292L,        211L,
               3.336,         354L,          235L,         328L,         250L,       245L,        243L,
               3.342,         344L,          233L,         335L,           0L,       257L,        218L,
               3.348,         473L,            0L,         437L,           0L,       281L,        213L,
               3.354,         474L,            0L,         228L,         200L,       311L,        193L,
                3.36,         414L,          274L,         370L,         229L,       205L,        202L,
               3.366,         335L,          185L,         285L,         207L,       316L,        277L,
               3.372,         507L,          161L,         321L,         226L,       327L,        172L,
               3.378,         285L,          236L,         498L,         259L,       383L,        173L,
               3.384,         477L,          202L,         179L,         241L,       253L,        210L,
                3.39,         336L,            0L,         251L,         191L,         0L,        167L
               )
head(HPLC_Data)
#> # A tibble: 6 x 7
#>    Time Control.16H `0.05mM.16H` `0.1mM.16H` `0.5mM.16H` `1mM.16H` `5.mM.16H`
#>   <dbl>       <int>        <int>       <int>       <int>     <int>      <int>
#> 1  3.09        2965         1409        2054        1380      1795       1135
#> 2  3.10        2830         1584        2278        1386      2232       1411
#> 3  3.10        2624         1574        2209        1232      1771       1331
#> 4  3.11        2763         1460        2294        1348      1969       1035
#> 5  3.12        3126         1467        2342        1386      1615       1370
#> 6  3.12        2947         1568        2354        1383      1924       1336
dim(HPLC_Data)
#> [1] 51  7

library(ggplot2)
library(ggridges)
library(tidyr)

HPLC_Data_Long <- gather(HPLC_Data, Sample, Absorbance, 2:7)
head(HPLC_Data_Long)
#> # A tibble: 6 x 3
#>    Time Sample      Absorbance
#>   <dbl> <chr>            <int>
#> 1  3.09 Control.16H       2965
#> 2  3.10 Control.16H       2830
#> 3  3.10 Control.16H       2624
#> 4  3.11 Control.16H       2763
#> 5  3.12 Control.16H       3126
#> 6  3.12 Control.16H       2947

ggplot(HPLC_Data_Long, aes(x = Absorbance, y = Sample)) + 
  geom_density_ridges()
#> Picking joint bandwidth of 308


ggplot(HPLC_Data_Long, aes(x = Time, y = Absorbance)) + 
  geom_point() +
  geom_smooth() +
  facet_grid(~ Sample)
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'

Created on 2021-01-05 by the reprex package (v0.3.0)

HTH

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.