R ggplot2 line two rows and all columns - r

I have this dataset:
structure(list(AgeGroup = c("Old", "Young"), Point.1 = c(0.401899407258065,
0.432845035714286), Point.2 = c(0.435610404, 0.448826385964912
), Point.3 = c(0.466951088, 0.473339649122807), Point.4 = c(0.490997664,
0.505416649122807), Point.5 = c(0.51047508, 0.517228789473684
), Point.6 = c(0.519614064, 0.520077087719298), Point.7 = c(0.524924236,
0.522939438596491), Point.8 = c(0.535448152, 0.523846929824561
), Point.9 = c(0.539298204, 0.529132140350877), Point.10 = c(0.546288992,
0.535221877192982), Point.11 = c(0.552286756, 0.544069684210526
), Point.12 = c(0.548644056, 0.547988701754386), Point.13 = c(0.546028996,
0.556100789473684), Point.14 = c(0.551464336, 0.557342807017544
), Point.15 = c(0.55835804, 0.552995140350877), Point.16 = c(0.560958056,
0.555753035087719), Point.17 = c(0.566631508, 0.553254912280702
), Point.18 = c(0.573644824, 0.557015719298246), Point.19 = c(0.579504268,
0.560797315789474), Point.20 = c(0.583600364, 0.560459526315789
), Point.21 = c(0.591889884, 0.563138245614035), Point.22 = c(0.598549332,
0.578847140350877), Point.23 = c(0.605920632, 0.59655149122807
), Point.24 = c(0.612308084, 0.611475473684211), Point.25 = c(0.618838952,
0.627695631578947), Point.26 = c(0.626865524, 0.640329719298246
), Point.27 = c(0.634642932, 0.642362438596491), Point.28 = c(0.639958892,
0.640706877192982), Point.29 = c(0.642219468, 0.654251789473684
), Point.30 = c(0.651740076, 0.674775824561404), Point.31 = c(0.657197604,
0.679311385964912), Point.32 = c(0.657618572, 0.673946421052632
), Point.33 = c(0.653554616, 0.67093849122807), Point.34 = c(0.648990388,
0.673238403508772), Point.35 = c(0.643885328, 0.669246245614035
), Point.36 = c(0.636234632, 0.670007543859649), Point.37 = c(0.632127604,
0.667657561403509), Point.38 = c(0.631252172, 0.665906228070175
), Point.39 = c(0.637404984, 0.677649561403509), Point.40 = c(0.6451598,
0.679067614035088), Point.41 = c(0.648019716, 0.688604824561403
), Point.42 = c(0.645375244, 0.692729175438596), Point.43 = c(0.647187664,
0.691994543859649), Point.44 = c(0.651923432, 0.681522859649123
), Point.45 = c(0.650062976, 0.674073456140351), Point.46 = c(0.638525956,
0.660092263157895), Point.47 = c(0.627772732, 0.652689456140351
), Point.48 = c(0.615988064, 0.650307087719298), Point.49 = c(0.599147952,
0.651349771929825), Point.50 = c(0.584897698795181, 0.63722649122807
)), class = "data.frame", row.names = c(NA, -2L))
which a subset of the 50 points looks like:
AgeGroup Point.1 Point.2 Point.3 Point.4 Point.5 Point.6 Point.7 Point.8 Point.9 Point.10 Point.11 Point.12 Point.13 Point.14 Point.15 Point.16
1 Old 0.4018994 0.4356104 0.4669511 0.4909977 0.5104751 0.5196141 0.5249242 0.5354482 0.5392982 0.5462890 0.5522868 0.5486441 0.5460290 0.5514643 0.5583580 0.5609581
2 Young 0.4328450 0.4488264 0.4733396 0.5054166 0.5172288 0.5200771 0.5229394 0.5238469 0.5291321 0.5352219 0.5440697 0.5479887 0.5561008 0.5573428 0.5529951 0.5557530
I am having difficulty plotting all columns on one graph, where X is just 1:50 tick marks and Y is the value of each point, color coded by AgeGroup.
I have tried melt, but I dont think thats necessary as it transposes the data and doubles the Point values.
I've tried variations of the following:
ggplot(YaxL, aes(x=1:50,y=YaxL[2:51])) + geom_point()
and
ggplot(YaxL, aes(x = 1:50)) +
geom_line(aes(y = YaxLDF[1,1], colour = "Old")) +
geom_line(aes(y = YaxLDF[2,1], colour = "Young"))
I feel like I'm overthinking this, help appreciated.

Try this approach. You can reshape to long with pivot_longer() and use the separate() function to extract the point position. After that the design of the plot is very practical. I have used the data you shared as YaxL. Always first try to reshape your data and then the plots can be easily built. Here the code:
library(tidyverse)
#Data process and plot
YaxL %>% pivot_longer(-1) %>%
separate(name,c('name','x'),sep='\\.') %>%
mutate(x=as.numeric(x)) %>%
dplyr::select(-name) %>%
ggplot(aes(x=x,y=value,color=AgeGroup,group=AgeGroup))+
geom_point()
Output:

Related

create a column and index it with an ID in R

I have several datasets that needs label (i.e., ID1 .. IDn). For example the following code belongs to a certain dataset where I just want to add an extra column that labels all the observations with IDx.
In total I got 42 datasets. This means that I need to label al of those 42 datasets with an unique ID.
structure(list(X = 1:5, x1.time = c("00:00:00", "00:01:00", "00:02:00",
"00:03:00", "00:04:00"), x1.AI_mean = c(0.323351574525762, 0.284159071937747,
0.239749146757921, 0.230766586001914, 0.244456920325771), x1.MAD_mean = c(0.00341506508299082,
0.00302928679541095, 0.00278424196850715, 0.00269385572703841,
0.00270493856606347), x1.SD_mean = c(0.00477593690534784, 0.00405971881709533,
0.00354415353173061, 0.00350825365755234, 0.00361817148789133
), x1.ENMO_t_mean = c(0.0239268821264327, 0.0237063614378219,
0.0237014797190142, 0.0239896011495783, 0.0243401417506231),
x2.AI_mean = c(0.294080313622427, 0.477944468152524, 0.260808829802468,
0.456214057286552, 0.84614872784907), x2.MAD_mean = c(0.00263194956522427,
0.00393549027910995, 0.00242397010624937, 0.00473452632379309,
0.00967936115719858), x2.SD_mean = c(0.00620183543213348,
0.00897436349787661, 0.00376656976842411, 0.0102128144373202,
0.026857971881988), x2.ENMO_t_mean = c(0.0152786778953128,
0.0134201176591068, 0.0105504453766938, 0.0126154127095435,
0.0194672090503613), x3.AI_mean = c(0.0735792814229227, 0.0514050450635112,
0.105131723525748, 0.128627572902289, 0.402271889323791),
x3.MAD_mean = c(0.00139436591181368, 0.000712147674432812,
0.00119105634569394, 0.00119348650394604, 0.00356665669204264
), x3.SD_mean = c(0.00199624824940588, 0.00120092927705721,
0.00193145315212752, 0.0019283335835232, 0.00656874765265735
), x3.ENMO_t_mean = c(0.0139865818700652, 0.0139851935882149,
0.0139915889947178, 0.01398633901765, 0.0144706584272194),
x4.AI_mean = c(0.0156678651943813, 0.0486531274165618, 0.033482857018396,
0.0377258494079243, 0.0678175492814511), x4.MAD_mean = c(0.000251120428854605,
0.000562880039987649, 0.000528793978359871, 0.00124991974998928,
0.000757489838974229), x4.SD_mean = c(0.000533766751727111,
0.00134959539056406, 0.000857977081466285, 0.00213180063264727,
0.00127973763932144), x4.ENMO_t_mean = c(0.0207155829098077,
0.020761171880961, 0.0207540203103165, 0.0202677052046802,
0.0198891636700763), x5.AI_mean = c(0.117604774640621, 0.0670305430061501,
0.0341376355863943, 0.13364297618809, 0.306972659040445),
x5.MAD_mean = c(0.0014759342409207, 0.000989910934380608,
0.000403358793801372, 0.00146211525459881, 0.00279101071524453
), x5.SD_mean = c(0.00332215932515048, 0.00195612286464375,
0.00100728633289468, 0.00269074473283573, 0.00460104621279968
), x5.ENMO_t_mean = c(0.0154521138471442, 0.0154613646883262,
0.0154478187295753, 0.0157331526286594, 0.0158523807067694
), x6.AI_mean = c(0.100509771506111, 0.0758254065303984,
0.116304451335499, 0.128055772822219, 0.121857857811461),
x6.MAD_mean = c(0.000820743353091489, 0.000853723738604472,
0.00106905689779995, 0.00125348246046243, 0.00132633070226373
), x6.SD_mean = c(0.00122240006684591, 0.00122098986196308,
0.00200131128161969, 0.00174469241955932, 0.00180918568232773
), x6.ENMO_t_mean = c(0.0105689413754299, 0.0104679319373477,
0.0106510201902777, 0.0105852542321717, 0.0110441830680727
), x7.AI_mean = c(0.0286478750449268, 0.0515922904718244,
0.0711332148199368, 0.05020475938917, 0.0830762493042348),
x7.MAD_mean = c(0.000363376272209463, 0.000480238540942994,
0.000628916162718124, 0.000594606941057317, 0.000878481811277494
), x7.SD_mean = c(0.000583562490557928, 0.000759472323982701,
0.00117176811747496, 0.00112513562674996, 0.00137098279570074
), x7.ENMO_t_mean = c(0.0179026688120152, 0.0178767746038774,
0.0174193867673969, 0.0172732431081777, 0.0173507218269879
)), row.names = c(NA, 5L), class = "data.frame")

Need help plotting data in R. I would like to plot each "rowname" as a line [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have a data.frame similar to this table:
Gene P1 P2 P3
A1 6 8 2
A2 12 6 3
A3 8 4 8
But, the word "Gene" is not in the data.frame. A1, A2, and A3 are the rownames.
Anyways, I would like to plot each "Gene" (i.e., each rowname) as a line in a graph where the x-axis corresponds to the Ps (i.e., P1, P2, and P3) and the y-axis corresponds to the values.
I included a picture of my RStudio that shows my data.frame.
Thank you.
Using this code:
library(tidyverse)
df1 <- structure(list(Pool_1.sf = c(1.04654112319058, 0.908757359307814 ), Pool_10.sf = c(1.09143254057473, 0.763847944339038), Pool_11.sf = c(1.18750942376232, 0.970606492107592), Pool_12.sf = c(1.40039457695623, 0.987404435084985 ), Pool_13.sf = c(1.40110264045617, 1.05184583712403), Pool_14.sf = c(0.975272918230445, 1.05978729086064), Pool_15.sf = c(1.18870377730237, 1.350632186878 ), Pool_16.sf = c(1.25322756941453, 1.18822754009871), Pool_17.sf = c(1.29750766166164, 0.561735111884727), Pool_18.sf = c(1.27533917021409, 1.38423737777244 ), Pool_19.sf = c(0.918846998358604, 0.95201145069032), Pool_2.sf = c(0.748425883461423, 0.618517135274528), Pool_20.sf = c(1.35027456541736, 1.11503741384757 ), Pool_21.sf = c(1.06155444204363, 0.991570644521018), Pool_22.sf = c(1.64504600710891, 1.07862501013554), Pool_23.sf = c(1.51097405304331, 0.971834605384123 ), Pool_24.sf = c(1.18420663655483, 0.881393761143161), Pool_25.sf = c(0.925122055385438, 0.93313232911786), Pool_26.sf = c(2.12016328112954, 0.829308431444176 ), Pool_27.sf = c(1.59552456085871, 0.705278334816745), Pool_28.sf = c(1.75141617967796, 0.863808031900547), Pool_29.sf = c(1.71320920062242, 0.782291400605908 ), Pool_3.sf = c(1.09209110640701, 0.776979928448013), Pool_30.sf = c(0.925564956736256, 0.905870068022084), Pool_31.sf = c(1.00114849632652, 0.713896646497438 ), Pool_32.sf = c(0.769653226223374, 1.01812180736834), Pool_33.sf = c(1.64152662148587, 0.912970524890157), Pool_34.sf = c(1.39446534544181, 0.892464822723893 ), Pool_35.sf = c(1.36553718507047, 0.709121064448927), Pool_36.sf = c(1.48178605247809, 0.766690878721894), Pool_37.sf = c(1.05050355917415, 0.862090327153509 ), Pool_38.sf = c(1.36989138311191, 1.01473830511752), Pool_39.sf = c(1.42872045770954, 1.13176474162602), Pool_4.sf = c(1.11960747784989, 0.665514805707436 ), Pool_40.sf = c(1.90897625098439, 1.28419857359682), Pool_41.sf = c(1.2570145072185, 0.987813170293439), Pool_43.sf = c(1.14927112622372, 1.33241620047574 ), Pool_44.sf = c(1.02884805988699, 1.1077339415536), Pool_45.sf = c(1, 1), Pool_46.sf = c(1.15692580371101, 1.01663753799148), Pool_47.sf = c(1.02161799920975, 0.893420612254083), Pool_48.sf = c(0.991350522776138, 0.857531005677309 ), Pool_49.sf = c(0.666054364361721, 0.95128169066564), Pool_5.sf = c(1.27677591889858, 0.65869398169343), Pool_50.sf = c(1.04592846997826, 0.820965050229932 ), Pool_51.sf = c(1.46227623256989, 1.16138433421938), Pool_52.sf = c(1.1826746106421, 1.33429257056276), Pool_53.sf = c(1.16041540250292, 0.878127525893012 ), Pool_54.sf = c(1.14285567434696, 0.870429885808645), Pool_55.sf = c(1.40863161629042, 0.485422488325543), Pool_56.sf = c(1.81157566249543, 0.519084970767436 ), Pool_58.sf = c(1.69798017279487, 1.34651488521988), Pool_59.sf = c(1.55336058362464, 0.982570924872293), Pool_6.sf = c(0.769881996423631, 0.388931536871056 ), Pool_60.sf = c(1.36877679300045, 1.02579768967408), Pool_61.sf = c(1.34960258409398, 0.983191813100761), Pool_62.sf = c(1.08159654058587, 0.76318904250517 ), Pool_63.sf = c(1.98209270942409, 1.05152970776951), Pool_64.sf = c(1.86946484050877, 1.06489241167699), Pool_65.sf = c(1.48159508541161, 0.89626404845365 ), Pool_66.sf = c(1.42400489307256, 1.30732410445944), Pool_7.sf = c(1.17869553929846, 0.620813490764102), Pool_8.sf = c(1.35783021860687, 0.77620120083204 ), Pool_9.sf = c(1.32884787662603, 0.758057408306258)), row.names = c("Glyma.01G000400", "Glyma.01G000900"), class = "data.frame")
df1 %>%
rownames_to_column() %>%
pivot_longer(cols = -c(rowname)) %>%
mutate(name = factor(name, levels = unique(name))) %>%
ggplot(aes(x = name, y = value, group = rowname, color = rowname)) +
geom_line() +
theme(axis.text.x = element_text(angle = 45, hjust = 1.05))
I get this plot:
Is this what you want? Otherwise, what do you want to change?

How to make a nice 3D plot in R for time series spectral data

I am trying to do a nice 3D plot using time series UV-Vis spectral data, like the first 3D graph below.
I used dput() function to show my data as below.
dput(head(Data))
and get:
structure(list(Wavelength = c(250, 252.5, 255, 257.5, 260, 262.5
), Date = structure(c(1365465600, 1365552000, 1365638400, 1365724800,
1365811200, 1365897600), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
X250 = c(25.736217791411, 25.1182597222222, 24.8889567642957,
24.4881150070126, 24.2313916666667, 24.0346564673157), X252.5 = c(25.2168558282209,
24.6022625, 24.375429567643, 23.979541374474, 23.7248569444444,
23.5341668984701), X255 = c(24.6049539877301, 23.9896638888889,
23.7649888423989, 23.3753758765778, 23.1248263888889, 22.9342726008345
), X257.5 = c(24.0257944785276, 23.4037875, 23.1804435146443,
22.795541374474, 22.5493486111111, 22.35478581363), X260 = c(23.5917024539877,
22.9615486111111, 22.7389818688982, 22.3544109396914, 22.1091222222222,
21.9127635605007), X262.5 = c(23.1529110429448, 22.5264,
22.3051380753138, 21.924920056101, 21.6777583333333, 21.4858831710709
), X265 = c(22.5382085889571, 21.918125, 21.6982092050209,
21.3252145862553, 21.0800125, 20.8941794158554), X267.5 = c(21.8748957055215,
21.2488722222222, 21.0308619246862, 20.6643941093969, 20.4225541666667,
20.2340041724617), X270 = c(21.2791380368098, 20.6435263888889,
20.4248619246862, 20.0633674614306, 19.823075, 19.6308664812239
), X272.5 = c(20.7223159509202, 20.0815388888889, 19.8637377963738,
19.5049382889201, 19.2644375, 19.0733532684284), X275 = c(20.1307699386503,
19.4878583333333, 19.2719930264993, 18.9178920056101, 18.6778583333333,
18.487123783032), X277.5 = c(19.4758159509202, 18.8334013888889,
18.6168423988842, 18.2683702664797, 18.0308791666667, 17.8428414464534
), X280 = c(18.8002392638037, 18.1555375, 17.9391743375174,
17.5960126227209, 17.3601361111111, 17.1767204450626), X282.5 = c(18.1441809815951,
17.4953208333333, 17.2798758716876, 16.9426002805049, 16.7091777777778,
16.5276926286509), X285 = c(17.5349570552147, 16.8845097222222,
16.6697126917713, 16.337541374474, 16.1053763888889, 15.9246383866481
), X287.5 = c(16.8937300613497, 16.2423861111111, 16.0298493723849,
15.7046171107994, 15.4740472222222, 15.2938845618915), X290 = c(16.2328404907975,
15.582175, 15.3718940027894, 15.0537826086957, 14.8253291666667,
14.646668984701), X292.5 = c(15.5751472392638, 14.9258291666667,
14.7170446304045, 14.4051360448808, 14.1804194444444, 14.0051933240612
), X295 = c(14.9421717791411, 14.2904180555556, 14.0835034867504,
13.778301542777, 13.5566902777778, 13.3817329624478), X297.5 = c(14.4052392638037,
13.7537152777778, 13.5474421199442, 13.2471725105189, 13.0260375,
12.8530055632823), X300 = c(13.9050889570552, 13.2578347222222,
13.0537364016736, 12.7592973352034, 12.5405888888889, 12.3732670375522
), X302.5 = c(13.401036809816, 12.7586194444445, 12.5570264993026,
12.2684992987377, 12.0533902777778, 11.8884353268428), X305 = c(12.902717791411,
12.2623319444444, 12.0613933054393, 11.7787826086956, 11.5651972222222,
11.4043337969402), X307.5 = c(12.4249355828221, 11.7857791666667,
11.5858940027894, 11.3107840112202, 11.0999777777778, 10.9374005563282
), X310 = c(11.9935245398773, 11.3549347222222, 11.1571324965133,
10.8868260869565, 10.67955, 10.5179193324061), X312.5 = c(11.6203098159509,
10.9819680555556, 10.7849539748954, 10.516744740533, 10.3119236111111,
10.156892906815), X315 = c(11.2705674846626, 10.63485, 10.4406555090656,
10.177301542777, 9.97497638888889, 9.82023783031989), X317.5 = c(10.9098711656442,
10.2797055555556, 10.0875216178522, 9.82828471248247, 9.62720138888889,
9.47325173852573), X320 = c(10.5516625766871, 9.922075, 9.73211157601116,
9.47973772791024, 9.28055, 9.12974826147427), X322.5 = c(10.2039049079755,
9.57341805555556, 9.38568758716876, 9.13822159887798, 8.94393888888889,
8.79378581363004), X325 = c(9.86461042944785, 9.23893472222222,
9.05190516039052, 8.80583450210379, 8.61297777777778, 8.46346731571627
), X327.5 = c(9.5730490797546, 8.95366388888889, 8.76786750348675,
8.52597615708275, 8.33285972222222, 8.18865924895688), X330 = c(9.29567791411043,
8.67920416666667, 8.49494421199442, 8.25632117812062, 8.06634305555556,
7.92368984700974), X332.5 = c(9.0010981595092, 8.38594305555556,
8.20200139470014, 7.96879803646564, 7.78189166666667, 7.63967593880389
), X335 = c(8.71511349693252, 8.09972916666667, 7.92145885634589,
7.69297335203366, 7.50750694444444, 7.3643421418637), X337.5 = c(8.45265644171779,
7.84026666666667, 7.66316178521618, 7.43814305750351, 7.25333333333333,
7.11477607788595), X340 = c(8.19838036809816, 7.59187361111111,
7.41271827057183, 7.19209256661992, 7.00985416666667, 6.87590959666203
), X342.5 = c(7.95462883435583, 7.34913194444444, 7.17332914923291,
6.95607433380084, 6.77643055555556, 6.64161752433936), X345 = c(7.72929754601227,
7.12695138888889, 6.95060669456067, 6.7338920056101, 6.55681388888889,
6.42844089012517), X347.5 = c(7.50222699386503, 6.90189583333333,
6.72852022315202, 6.51498036465638, 6.33897916666667, 6.21110848400556
), X350 = c(7.2898527607362, 6.69248472222222, 6.52281171548117,
6.3138920056101, 6.13989722222222, 6.00979554937413), X352.5 = c(7.07927300613497,
6.48439166666667, 6.31443514644351, 6.10986956521739, 5.93754583333333,
5.81149652294854), X355 = c(6.86355214723926, 6.26889861111111,
6.09972524407252, 5.89783450210379, 5.72706527777778, 5.60363838664812
), X357.5 = c(6.6658527607362, 6.07161111111111, 5.90622873082287,
5.70649649368864, 5.53700833333333, 5.41251877607789), X360 = c(6.47400613496932,
5.88162777777778, 5.71633472803347, 5.5187713884993, 5.35024444444444,
5.22833796940195), X362.5 = c(6.30347852760736, 5.71433888888889,
5.54859414225942, 5.3527587657784, 5.1863375, 5.06425173852573
), X365 = c(6.16322699386503, 5.57911527777778, 5.41753835425384,
5.22367601683029, 5.05854027777778, 4.94001390820584), X367.5 = c(6.02653067484663,
5.44968333333333, 5.29124267782427, 5.10030294530154, 4.93744305555556,
4.82315020862309), X370 = c(5.86248466257669, 5.28735277777778,
5.12692747559275, 4.93981065918654, 4.77878055555556, 4.6638066759388
), X372.5 = c(5.68123006134969, 5.10715, 4.94811854951185,
4.764904628331, 4.60323333333333, 4.48933379694019), X375 = c(5.53815644171779,
4.96720416666667, 4.81097350069735, 4.62871388499299, 4.46926944444445,
4.35810987482615), X377.5 = c(5.40510429447853, 4.8370625,
4.68262761506276, 4.50320617110799, 4.34814444444444, 4.23741724617524
), X380 = c(5.30138343558282, 4.73901805555556, 4.5846889818689,
4.40751612903226, 4.25314444444444, 4.14589847009736), X382.5 = c(5.20306134969325,
4.64154722222222, 4.49053417015342, 4.31611079943899, 4.16125138888889,
4.05445757997218), X385 = c(5.07416871165644, 4.515375, 4.3646959553696,
4.19456802244039, 4.04227222222222, 3.93332127955494), X387.5 = c(4.96219325153374,
4.40868194444444, 4.25931520223152, 4.0922889200561, 3.9414,
3.83277607788595), X390 = c(4.83940797546012, 4.29276527777778,
4.14653974895398, 3.97920196353436, 3.82955277777778, 3.72600834492351
), X392.5 = c(4.71031288343558, 4.16622083333333, 4.02140446304045,
3.85572510518934, 3.70953194444445, 3.60538386648122), X395 = c(4.62059202453988,
4.07360138888889, 3.92935564853556, 3.76849228611501, 3.62277638888889,
3.51784283727399), X397.5 = c(4.49155521472393, 3.95385972222222,
3.81216178521618, 3.65344039270687, 3.50810833333333, 3.4116926286509
), X400 = c(4.37370858895706, 3.84129861111111, 3.70030125523013,
3.5432286115007, 3.39975277777778, 3.30254659248957), X402.5 = c(4.27044171779141,
3.738875, 3.59841562064156, 3.4434095371669, 3.30132638888889,
3.20369819193324), X405 = c(4.15562883435583, 3.6327375,
3.49318270571827, 3.33822159887798, 3.19675555555555, 3.10537273991655
), X407.5 = c(4.09877607361963, 3.57864305555556, 3.44027057182706,
3.28816129032258, 3.14875138888889, 3.05293602225313), X410 = c(4.01044785276074,
3.48679444444444, 3.35288842398884, 3.20463534361851, 3.06820833333333,
2.9671752433936), X412.5 = c(3.87490797546012, 3.35905694444444,
3.2244839609484, 3.07484291725105, 2.93775416666667, 2.8437983310153
), X415 = c(3.79108282208589, 3.28507361111111, 3.14952161785216,
3.00085273492286, 2.86421805555555, 2.77412378303199), X417.5 = c(3.68693558282209,
3.17824583333333, 3.04701394700139, 2.9043366058906, 2.76995972222222,
2.67318358831711), X420 = c(3.56437116564417, 3.05670972222222,
2.92747419804742, 2.786095371669, 2.65226666666667, 2.55702225312935
), X422.5 = c(3.51319018404908, 3.00990694444444, 2.87744769874477,
2.73367180925666, 2.60142361111111, 2.51227399165508), X425 = c(3.43132208588957,
2.92941805555555, 2.80041562064156, 2.65933099579243, 2.52816388888889,
2.43237969401947), X427.5 = c(3.31023926380368, 2.81629166666667,
2.68912831241283, 2.54957363253857, 2.41817777777778, 2.33177051460362
), X430 = c(3.26191717791411, 2.77505833333333, 2.64634030683403,
2.50681767180926, 2.37668055555556, 2.29549374130737), X432.5 = c(3.22984662576687,
2.74605555555556, 2.61894979079498, 2.48168022440393, 2.35282083333333,
2.26610987482615), X435 = c(3.13996932515337, 2.65807916666667,
2.5333179916318, 2.39782187938289, 2.26921388888889, 2.18432684283727
), X437.5 = c(3.08235582822086, 2.60515833333333, 2.4803249651325,
2.34626928471248, 2.21812083333333, 2.13608901251739), X440 = c(3.01686809815951,
2.54044583333333, 2.41671548117155, 2.2833842917251, 2.16062083333333,
2.07232267037552), X442.5 = c(2.93285889570552, 2.46135694444444,
2.33697489539749, 2.20531837307153, 2.08016805555556, 1.99902225312935
), X445 = c(2.8908773006135, 2.42607361111111, 2.30482426778243,
2.17530014025245, 2.04767916666667, 1.97140194714882), X447.5 = c(2.85198466257669,
2.38861111111111, 2.2694839609484, 2.14013884992987, 2.01676111111111,
1.93308901251738), X450 = c(2.8046472392638, 2.34394583333333,
2.22286750348675, 2.09689481065919, 1.97544444444445, 1.89651043115438
), X452.5 = c(2.77545705521472, 2.31733333333333, 2.20150627615063,
2.07733800841515, 1.95440277777778, 1.87571627260083), X455 = c(2.71198159509203,
2.26175277777778, 2.14609483960948, 2.02168022440393, 1.90238194444444,
1.82506536856745), X457.5 = c(2.69071779141104, 2.24759861111111,
2.1283709902371, 2.0067461430575, 1.88878055555556, 1.81217802503477
), X460 = c(2.63857055214724, 2.19480416666667, 2.07814365411437,
1.95862833099579, 1.84296111111111, 1.76875243393602), X462.5 = c(2.55233742331288,
2.10490416666667, 1.99411854951185, 1.87502664796634, 1.76141805555556,
1.68473435326843), X465 = c(2.54993251533742, 2.10804166666667,
1.99814644351464, 1.88111360448808, 1.76530277777778, 1.68772322670375
), X467.5 = c(2.54192944785276, 2.10937638888889, 1.99570990237099,
1.88144319775596, 1.76786666666667, 1.69657162726008), X470 = c(2.45424233128834,
2.02388472222222, 1.91476011157601, 1.80086255259467, 1.68827638888889,
1.61762865090403), X472.5 = c(2.38808588957055, 1.96169583333333,
1.85649232914923, 1.74286956521739, 1.63194444444444, 1.56048400556328
), X475 = c(2.40716871165644, 1.98333055555556, 1.8761589958159,
1.7647840112202, 1.65609861111111, 1.58707093184979), X477.5 = c(2.38796012269939,
1.96411527777778, 1.85740725244073, 1.74938990182328, 1.64029444444444,
1.57306258692629), X480 = c(2.32367484662577, 1.90594027777778,
1.80042677824268, 1.69331276297335, 1.58667777777778, 1.51872322670375
), X482.5 = c(2.26839877300614, 1.85602638888889, 1.75232914923291,
1.64626928471248, 1.542725, 1.47292350486787), X485 = c(2.24077914110429,
1.82308194444444, 1.72304323570432, 1.61980925666199, 1.5158,
1.44215159944367), X487.5 = c(2.19346625766871, 1.77742916666667,
1.67717712691771, 1.57596213183731, 1.46934861111111, 1.39640751043115
), X490 = c(2.1796226993865, 1.77528611111111, 1.67270432357043,
1.56773772791024, 1.46491111111111, 1.39967732962448), X492.5 = c(2.19796932515337,
1.79399861111111, 1.69254253835425, 1.58660028050491, 1.48578888888889,
1.42326842837274), X495 = c(2.16203067484663, 1.75784722222222,
1.66087866108787, 1.56017812061711, 1.45659583333333, 1.39502364394993
), X497.5 = c(2.12128220858896, 1.72433055555556, 1.62827615062762,
1.52875175315568, 1.42800833333333, 1.36483727399165), X500 = c(2.10455214723926,
1.71279027777778, 1.61463458856346, 1.51266058906031, 1.41571388888889,
1.35290403337969), X502.5 = c(2.09321779141104, 1.70464027777778,
1.60352022315202, 1.50263674614306, 1.40064722222222, 1.34636300417246
), X505 = c(2.06455828220859, 1.67302916666667, 1.57388145048815,
1.47552734922861, 1.37514166666667, 1.31759944367177), X507.5 = c(2.01607975460123,
1.62675138888889, 1.53272524407252, 1.43562692847125, 1.34284444444444,
1.27975660639777), X510 = c(1.97671165644172, 1.59260694444444,
1.50193444909344, 1.41013043478261, 1.31677916666667, 1.25430876216968
), X512.5 = c(1.96352147239264, 1.57798472222222, 1.48636262203626,
1.39764375876578, 1.30225555555556, 1.23669680111266), X515 = c(1.92503987730061,
1.54797083333333, 1.45469456066946, 1.36199298737728, 1.26766805555556,
1.21219749652295), X517.5 = c(1.90465030674847, 1.53300555555556,
1.44391352859135, 1.35238569424965, 1.2612375, 1.20831293463143
), X520 = c(1.87689570552147, 1.50217916666667, 1.4149330543933,
1.32729733520337, 1.23678194444445, 1.17577329624478), X522.5 = c(1.83759202453988,
1.46538888888889, 1.37917015341702, 1.29119775596073, 1.20174861111111,
1.14477607788595), X525 = c(1.83651533742331, 1.46525, 1.38037935843794,
1.29450490883591, 1.2079125, 1.15156189151599), X527.5 = c(1.82067791411043,
1.45758472222222, 1.36769874476987, 1.28326788218794, 1.19442916666667,
1.13923365785814), X530 = c(1.7854754601227, 1.42325833333333,
1.33740446304045, 1.25485553997195, 1.16439166666667, 1.11009457579972
), X532.5 = c(1.72706134969325, 1.36137083333333, 1.28353277545328,
1.20330014025245, 1.1164875, 1.05959248956885), X535 = c(1.73546012269939,
1.37703333333333, 1.2953570432357, 1.21220617110799, 1.12938333333333,
1.07361335187761), X537.5 = c(1.75189570552147, 1.39752083333333,
1.3135160390516, 1.23146283309958, 1.15030416666667, 1.10116133518776
), X540 = c(1.70230061349693, 1.35148888888889, 1.2665369595537,
1.18725666199158, 1.10636944444444, 1.06070792767733), X542.5 = c(1.71566564417178,
1.36359027777778, 1.28287029288703, 1.20369565217391, 1.1235375,
1.07357719054242), X545 = c(1.66589877300613, 1.31230416666667,
1.23633891213389, 1.15782889200561, 1.07775833333333, 1.01979972183588
), X547.5 = c(1.62098466257669, 1.27635555555556, 1.19730962343096,
1.11939270687237, 1.03757361111111, 0.990175243393602), X550 = c(1.64088650306749,
1.30173333333333, 1.22275592747559, 1.14718793828892, 1.06357916666667,
1.02470931849791), X552.5 = c(1.65776687116564, 1.31616944444444,
1.23976708507671, 1.16367180925666, 1.08286944444444, 1.03624200278164
), X555 = c(1.64775766871166, 1.30469861111111, 1.23003905160391,
1.15642496493689, 1.07983611111111, 1.02301529902643), X557.5 = c(1.57864417177914,
1.24234861111111, 1.16718131101813, 1.09518373071529, 1.01922638888889,
0.966821974965229), X560 = c(1.55608895705521, 1.22404166666667,
1.14994979079498, 1.07797896213184, 0.998729166666667, 0.953904033379694
), X562.5 = c(1.57327300613497, 1.24271111111111, 1.17039748953975,
1.10076437587658, 1.02429722222222, 0.982093184979138), X565 = c(1.54155828220859,
1.21247638888889, 1.14011994421199, 1.06987377279102, 0.995325,
0.950226703755216), X567.5 = c(1.5184754601227, 1.19163194444444,
1.11808926080893, 1.04673772791024, 0.969984722222222, 0.920390820584145
), X570 = c(1.52191104294479, 1.19953472222222, 1.12552022315202,
1.05369144460028, 0.979043055555555, 0.936059805285118),
X572.5 = c(1.49422699386503, 1.17113333333333, 1.09843793584379,
1.02884291725105, 0.956215277777778, 0.914119610570236),
X575 = c(1.48120552147239, 1.16091666666667, 1.08878382147838,
1.02371248246844, 0.950745833333333, 0.903524339360223),
X577.5 = c(1.49473312883436, 1.17405, 1.10468340306834, 1.04081346423562,
0.967102777777778, 0.918347705146036), X580 = c(1.45893558282209,
1.13822638888889, 1.07150488145049, 1.004904628331, 0.931488888888889,
0.888706536856745), X582.5 = c(1.40335889570552, 1.08981666666667,
1.02136262203626, 0.955345021037868, 0.882438888888889, 0.842457579972184
), X585 = c(1.41981901840491, 1.11120277777778, 1.04046164574617,
0.976112201963534, 0.902045833333333, 0.854774687065369),
X587.5 = c(1.44122085889571, 1.13389722222222, 1.06531938633194,
0.998193548387097, 0.927052777777778, 0.884666203059805),
X590 = c(1.43262883435583, 1.12188472222222, 1.05589539748954,
0.991642356241234, 0.923915277777778, 0.883214186369958),
X592.5 = c(1.39457668711656, 1.08495694444444, 1.01676150627615,
0.954368863955119, 0.886066666666667, 0.842401947148818),
X595 = c(1.39473006134969, 1.09030138888889, 1.02193584379358,
0.95813744740533, 0.889866666666667, 0.851438108484006),
X597.5 = c(1.39176380368098, 1.08874305555556, 1.02160251046025,
0.960784011220196, 0.891755555555556, 0.851367176634214),
X600 = c(1.32321472392638, 1.02342361111111, 0.958054393305439,
0.896713884992987, 0.828456944444444, 0.789112656467316),
X602.5 = c(1.3699754601227, 1.06539861111111, 1.00389818688982,
0.94194950911641, 0.875038888888889, 0.832920723226704),
X605 = c(1.39004294478528, 1.0856125, 1.02410460251046, 0.964893408134642,
0.897881944444444, 0.851397774687065), X607.5 = c(1.33887423312883,
1.04344305555556, 0.978672245467225, 0.918176718092567, 0.853443055555556,
0.810876216968011), X610 = c(1.34292944785276, 1.04911111111111,
0.98465690376569, 0.922030855539972, 0.858780555555556, 0.820618915159944
), X612.5 = c(1.32123006134969, 1.02857083333333, 0.962319386331939,
0.899249649368864, 0.834901388888889, 0.797037552155772),
X615 = c(1.30576380368098, 1.01544166666667, 0.949560669456067,
0.889232819074334, 0.824005555555556, 0.787675938803894),
X617.5 = c(1.30801840490798, 1.01950138888889, 0.959458856345886,
0.902255259467041, 0.839116666666667, 0.80459388038943),
X620 = c(1.25273619631902, 0.963565277777778, 0.903634588563459,
0.845955119214586, 0.781859722222222, 0.751739916550765),
X622.5 = c(1.24233742331288, 0.951993055555556, 0.889652719665272,
0.832720897615708, 0.765165277777778, 0.728485396383866),
X625 = c(1.3115736196319, 1.020975, 0.960577405857741, 0.902300140252454,
0.835329166666667, 0.789098748261474), X627.5 = c(1.32251840490798,
1.03869861111111, 0.977846582984658, 0.916507713884993, 0.852429166666667,
0.812655076495132), X630 = c(1.26833435582822, 0.9928125,
0.93086750348675, 0.87539270687237, 0.812751388888889, 0.775739916550765
), X632.5 = c(1.24898773006135, 0.965934722222222, 0.908059972105997,
0.85682889200561, 0.794722222222222, 0.751435326842837),
X635 = c(1.28299386503067, 0.995876388888889, 0.936375174337517,
0.881263674614306, 0.819331944444444, 0.78326842837274),
X637.5 = c(1.2784018404908, 1.00060833333333, 0.939645746164575,
0.880981767180926, 0.821463888888889, 0.792333796940195),
X640 = c(1.24037116564417, 0.960616666666667, 0.905357043235704,
0.846816269284712, 0.787144444444444, 0.744055632823366),
X642.5 = c(1.19373619631902, 0.907856944444444, 0.852075313807531,
0.797594670406732, 0.732779166666667, 0.684244784422809),
X645 = c(1.17663190184049, 0.898422222222222, 0.835518828451883,
0.782708274894811, 0.717233333333333, 0.684310152990264),
X647.5 = c(1.21073619631902, 0.943138888888889, 0.879875871687587,
0.826015427769986, 0.7630125, 0.737840055632823), X650 = c(1.20088036809816,
0.934829166666667, 0.877008368200837, 0.821608695652174,
0.760254166666667, 0.727004172461752), X652.5 = c(1.18600920245399,
0.915881944444444, 0.860887029288703, 0.80358064516129, 0.744027777777778,
0.705867872044506), X655 = c(1.22061349693252, 0.951930555555556,
0.896224546722455, 0.840730715287518, 0.784806944444444,
0.750878998609179), X657.5 = c(1.19243865030675, 0.924801388888889,
0.865479776847978, 0.81258064516129, 0.757759722222222, 0.721283727399165
), X660 = c(1.10550920245399, 0.841702777777778, 0.780730822873082,
0.731366058906031, 0.673393055555556, 0.638547983310153)), row.names = c(NA,
6L), class = "data.frame")
My code:
Data <- data.frame(Data)
library(rgl)
library(pls)
x <- as.POSIXct(Data$Date, format = "2013-01-10", tz = "Australia/Adelaide")
y <- Data$Wavelength
z <- as.matrix(Data[,3:167])
open3d()
plot3d(x, y, z,col="purple", size=3, xlab = "Date", ylab = "Wavelength", zlab = "Absorbance (/cm)")
I get a not very nice plot as shown in the second graph.
The x-axis has labels in numerical dates, but I want the actual dates in the format like "1 June 2013" or "1/6/2013".
I also don't know how to make a nice rainbow colour looking 3D graph.
Any help is welcome :)
a typical UV-Vis spectrum looks like graph 3 below
using the codes provided by Marco Sandri,
library(tidyr)
library(ggplot2)
library(plotly)
Data %>%
gather(Series, y, X250:X660, factor_key=TRUE) %>%
plot_ly(x = ~Date, y = ~Wavelength, z = ~y,
type = 'scatter3d', mode = 'lines', color = ~Series)
The graph 4 is the plot I get.
A solution based on the plotly package:
library(tidyr)
library(plotly)
Data %>%
gather(Series, y, X250:X660, factor_key=TRUE) %>%
plot_ly(x = ~Date, y = ~Wavelength, z = ~y, type = 'scatter3d', mode = 'lines', color = ~Series)
You may omit and redraw the axes using bbox3d. In bbox3d just xat= and xlab= specifications are needed, where we use x.
open3d()
plot3d(x, y, z, col="purple", size=3, xlab="Date", ylab="Wavelength",
zlab="Absorbance (/cm)", axes=FALSE, top=TRUE)
bbox3d(xat=x, xlab=x, col="black", front="line", back="line", lit=FALSE)

Create a multiline plot from a dataset with time on one axis and genes on the other

I have a dataset with mean gene counts for each decade as shown below:
structure(list(decade_0 = c(92.500989948184, 2788.27384875413,
28.6937227408861, 1988.03831525414, 1476.83143096418), decade_1 = c(83.4606306426572,
537.725421951383, 10.2747132062782, 235.380422949258, 685.043600629146
), decade_2 = c(188.414375201462, 2091.84249935145, 17.080858894829,
649.55107199935, 1805.3484565514), decade_3 = c(43.3316024314987,
141.64396529835, 2.77851259926935, 94.7748265692319, 413.248354335235
), decade_4 = c(54.4891626582901, 451.076574268175, 12.4298374245007,
346.102609621018, 769.215535857077), decade_5 = c(85.5621750431284,
131.822699578988, 13.3130607062134, 151.002200923853, 387.727911723968
), decade_6 = c(112.860998806804, 4844.59668489898, 19.7317645111144,
2084.76584309876, 766.375852567831), decade_7 = c(73.2198969730458,
566.042952305845, 3.2457873699886, 311.853982701609, 768.801733767044
), decade_8 = c(91.8161648275608, 115.161700090147, 10.7289451320065,
181.747670625714, 549.21661120626), decade_9 = c(123.31045087146,
648.23694540667, 17.7690326882018, 430.301803845829, 677.187054208271
)), row.names = c("ANK1", "NTN4", "PTPRH", "JAG1", "PLAT"), class = "data.frame")
I would like to plot a line graph with the changes in counts over time for each of >30 genes as shown here in excel.
To do this with ggplot I have to convert it to col1: decade, col2: gene, col3: counts.
My question is, either how to convert my table into this ggplot friendly table, or if there is a better way to produce the plot with a different tool?
Thanks!
One possibility: transpose your data frame, convert rownames to columns, then gather ("make long"). Plotting is then easy.
library(tidyverse)
mydat <- structure(list(decade_0 = c(92.500989948184, 2788.27384875413,
28.6937227408861, 1988.03831525414, 1476.83143096418), decade_1 = c(83.4606306426572,
537.725421951383, 10.2747132062782, 235.380422949258, 685.043600629146
), decade_2 = c(188.414375201462, 2091.84249935145, 17.080858894829,
649.55107199935, 1805.3484565514), decade_3 = c(43.3316024314987,
141.64396529835, 2.77851259926935, 94.7748265692319, 413.248354335235
), decade_4 = c(54.4891626582901, 451.076574268175, 12.4298374245007,
346.102609621018, 769.215535857077), decade_5 = c(85.5621750431284,
131.822699578988, 13.3130607062134, 151.002200923853, 387.727911723968
), decade_6 = c(112.860998806804, 4844.59668489898, 19.7317645111144,
2084.76584309876, 766.375852567831), decade_7 = c(73.2198969730458,
566.042952305845, 3.2457873699886, 311.853982701609, 768.801733767044
), decade_8 = c(91.8161648275608, 115.161700090147, 10.7289451320065,
181.747670625714, 549.21661120626), decade_9 = c(123.31045087146,
648.23694540667, 17.7690326882018, 430.301803845829, 677.187054208271
)), row.names = c("ANK1", "NTN4", "PTPRH", "JAG1", "PLAT"), class = "data.frame")
newdat <- mydat %>% t() %>% as.data.frame() %>% tibble::rownames_to_column('decade') %>%
pivot_longer(-decade, names_to = 'gene', values_to = 'count')
ggplot(newdat) + geom_line(aes(decade, count, color = gene, group = gene))
Created on 2020-02-14 by the reprex package (v0.3.0)

Retrieve the position (column name) of the maximum value of the derivative of an interval

To calculate the Red Edge Position Index, I need to find the wavelength value (column name) corresponding to the maximum derivative of reflectance in the red edge region from 690nm to 740nm. I have included a subset of my dataframe below, it contains the correct interval...
I have 640 rows (Sample) of 2151 measurements (values) plus a few catagoricals in the first columns (e.g. plantType and plantCondition). I need to find the column of the value corresponding to the maximum of the derivative of the values in the interval specified and return the wavelength value to the REPI column.
I am trying something like this but I do not know how to calculate the maximum of the derivative in the specified interval
# find the maximum of the derivative of the values in columns x690:x740
# attempt to find for single sample first
> which( colnames(spec.data)=="X690")
[1] 352
> which( colnames(spec.data)=="X740")
[1] 402
# I want to return the values of the differential but this doesn't work
> foo.vector <- diff(spec.data[1,352:402])
>> Error in r[i1] - r[-length(r):-(length(r) - lag + 1L)] : non-numeric argument to binary operator
This makes sense because I don't have the dt in dx/dt but I am not sure how to retrieve the position of the maximum value of the derivative of this interval. once I did I think I would
> spec.data$REPI <- which( colnames(spec.data) == max(foo.vector))
Then I think I would lapply this for each row?
Can anyone point me towards a solution for this?
Thank you...
subset of data from dput
> dput(spec.data[1:2, c(1:3, 7, 300:450)])
structure(list(Sample = c("JUMO_G1 P1T9 Leaf Clip00000.asd",
"JUMO_G1 P1T9 Leaf Clip00001.asd"), plantType = c("JUMO", "JUMO"
), plantCondition = c("G", "G"), REPI = c(NA_real_, NA_real_),
X638 = c(0.0611, 0.06114), X639 = c(0.0606, 0.06064), X640 = c(0.0601,
0.06012), X641 = c(0.0595, 0.05953), X642 = c(0.0589, 0.05893
), X643 = c(0.0584, 0.05834), X644 = c(0.0577, 0.05775),
X645 = c(0.05717, 0.05717), X646 = c(0.0566, 0.05664), X647 = c(0.0562,
0.05618), X648 = c(0.0557, 0.05573), X649 = c(0.0554, 0.05536
), X650 = c(0.0551, 0.05505), X651 = c(0.0547, 0.05475),
X652 = c(0.05448, 0.05447), X653 = c(0.0542, 0.05421), X654 = c(0.054,
0.05395), X655 = c(0.0536, 0.05357), X656 = c(0.0532, 0.05319
), X657 = c(0.0528, 0.05277), X658 = c(0.0523, 0.05229),
X659 = c(0.0518, 0.05176), X660 = c(0.05128, 0.05126), X661 = c(0.0508,
0.05077), X662 = c(0.0503, 0.05024), X663 = c(0.0498, 0.04978
), X664 = c(0.0494, 0.04936), X665 = c(0.049, 0.04897), X666 = c(0.04869,
0.04866), X667 = c(0.0484, 0.04838), X668 = c(0.0482, 0.04815
), X669 = c(0.048, 0.04797), X670 = c(0.0479, 0.04782), X671 = c(0.0478,
0.04775), X672 = c(0.0478, 0.04773), X673 = c(0.0478, 0.04773
), X674 = c(0.0478, 0.04776), X675 = c(0.0479, 0.04786),
X676 = c(0.0481, 0.04802), X677 = c(0.0483, 0.0482), X678 = c(0.0486,
0.04843), X679 = c(0.0489, 0.04873), X680 = c(0.04925, 0.04911
), X681 = c(0.0498, 0.04962), X682 = c(0.0504, 0.05026),
X683 = c(0.05122, 0.05103), X684 = c(0.0522, 0.052), X685 = c(0.0533,
0.05317), X686 = c(0.0548, 0.05458), X687 = c(0.05647, 0.05627
), X688 = c(0.0584, 0.05824), X689 = c(0.0608, 0.06057),
X690 = c(0.0634, 0.06326), X691 = c(0.0664, 0.06626), X692 = c(0.0698,
0.06958), X693 = c(0.0734, 0.07317), X694 = c(0.0773, 0.07701
), X695 = c(0.0814, 0.08109), X696 = c(0.0856, 0.0854), X697 = c(0.0901,
0.08989), X698 = c(0.0947, 0.09449), X699 = c(0.0994, 0.09917
), X700 = c(0.10417, 0.10395), X701 = c(0.10899, 0.10881),
X702 = c(0.11385, 0.11366), X703 = c(0.11871, 0.11854), X704 = c(0.12356,
0.12342), X705 = c(0.1284, 0.12829), X706 = c(0.13324, 0.13312
), X707 = c(0.13803, 0.13792), X708 = c(0.14281, 0.14273),
X709 = c(0.14763, 0.14755), X710 = c(0.15243, 0.15235), X711 = c(0.15718,
0.15713), X712 = c(0.16192, 0.16189), X713 = c(0.1667, 0.16663
), X714 = c(0.17143, 0.17137), X715 = c(0.17609, 0.17605),
X716 = c(0.18069, 0.18062), X717 = c(0.18528, 0.1852), X718 = c(0.18977,
0.18968), X719 = c(0.19417, 0.19406), X720 = c(0.19851, 0.19838
), X721 = c(0.20276, 0.20263), X722 = c(0.20686, 0.20671),
X723 = c(0.2108, 0.21063), X724 = c(0.21465, 0.21449), X725 = c(0.21837,
0.21819), X726 = c(0.22194, 0.22174), X727 = c(0.22534, 0.22515
), X728 = c(0.2286, 0.22838), X729 = c(0.23164, 0.23142),
X730 = c(0.23447, 0.23427), X731 = c(0.23719, 0.23696), X732 = c(0.23984,
0.23959), X733 = c(0.24229, 0.24203), X734 = c(0.24452, 0.24426
), X735 = c(0.24668, 0.24638), X736 = c(0.24867, 0.24839),
X737 = c(0.25053, 0.25028), X738 = c(0.25229, 0.25203), X739 = c(0.25382,
0.25359), X740 = c(0.25531, 0.25508), X741 = c(0.25672, 0.25646
), X742 = c(0.25791, 0.25766), X743 = c(0.25907, 0.25884),
X744 = c(0.26014, 0.25993), X745 = c(0.2611, 0.26089), X746 = c(0.26201,
0.26178), X747 = c(0.26278, 0.26257), X748 = c(0.26347, 0.26329
), X749 = c(0.26414, 0.26397), X750 = c(0.26475, 0.26459),
X751 = c(0.26525, 0.2651), X752 = c(0.26568, 0.26554), X753 = c(0.26614,
0.266), X754 = c(0.26652, 0.26639), X755 = c(0.26682, 0.26671
), X756 = c(0.2671, 0.26701), X757 = c(0.26743, 0.26734),
X758 = c(0.26767, 0.26758), X759 = c(0.26789, 0.26781), X760 = c(0.26814,
0.26808), X761 = c(0.2682, 0.26817), X762 = c(0.26835, 0.26831
), X763 = c(0.26856, 0.26851), X764 = c(0.26872, 0.26869),
X765 = c(0.26884, 0.26881), X766 = c(0.26892, 0.2689), X767 = c(0.26896,
0.26894), X768 = c(0.26898, 0.26896), X769 = c(0.2691, 0.26909
), X770 = c(0.2692, 0.2692), X771 = c(0.26921, 0.26921),
X772 = c(0.26923, 0.26926), X773 = c(0.26927, 0.26931), X774 = c(0.26935,
0.26939), X775 = c(0.26945, 0.26947), X776 = c(0.26946, 0.26949
), X777 = c(0.26948, 0.26952), X778 = c(0.26953, 0.26958),
X779 = c(0.26958, 0.26963), X780 = c(0.26965, 0.2697), X781 = c(0.2697,
0.26975), X782 = c(0.2697, 0.26977), X783 = c(0.26972, 0.26978
), X784 = c(0.26979, 0.26982), X785 = c(0.26987, 0.2699),
X786 = c(0.26991, 0.26998), X787 = c(0.26989, 0.26997), X788 = c(0.26991,
0.26998)), .Names = c("Sample", "plantType", "plantCondition",
"REPI", "X638", "X639", "X640", "X641", "X642", "X643", "X644",
"X645", "X646", "X647", "X648", "X649", "X650", "X651", "X652",
"X653", "X654", "X655", "X656", "X657", "X658", "X659", "X660",
"X661", "X662", "X663", "X664", "X665", "X666", "X667", "X668",
"X669", "X670", "X671", "X672", "X673", "X674", "X675", "X676",
"X677", "X678", "X679", "X680", "X681", "X682", "X683", "X684",
"X685", "X686", "X687", "X688", "X689", "X690", "X691", "X692",
"X693", "X694", "X695", "X696", "X697", "X698", "X699", "X700",
"X701", "X702", "X703", "X704", "X705", "X706", "X707", "X708",
"X709", "X710", "X711", "X712", "X713", "X714", "X715", "X716",
"X717", "X718", "X719", "X720", "X721", "X722", "X723", "X724",
"X725", "X726", "X727", "X728", "X729", "X730", "X731", "X732",
"X733", "X734", "X735", "X736", "X737", "X738", "X739", "X740",
"X741", "X742", "X743", "X744", "X745", "X746", "X747", "X748",
"X749", "X750", "X751", "X752", "X753", "X754", "X755", "X756",
"X757", "X758", "X759", "X760", "X761", "X762", "X763", "X764",
"X765", "X766", "X767", "X768", "X769", "X770", "X771", "X772",
"X773", "X774", "X775", "X776", "X777", "X778", "X779", "X780",
"X781", "X782", "X783", "X784", "X785", "X786", "X787", "X788"
), row.names = 1:2, class = "data.frame")
You can try this
spec.data$REPI <- apply(spec.data[,-(1:4)], 1, function(x) which.max(diff(x)))
Or you can try using dplyr and tidyr:
library(dplyr)
library(tidyr)
spec.data %>%
gather(key, value, -Sample, -plantType, - plantCondition, -REPI) %>%
group_by(Sample) %>%
summarise(which.max(diff(value)))
They both seem to give same results.

Resources