I want to make a plot from dataframe A using the plot() function from R. The columns in A are called "SNP_pos", "X", followed by 16 columns called "p0.5","p1.5","p2.5",..."p15.5".
plot(A$SNP_pos, -log10(A$p1.5),
type="p", cex = 0.6, pch = 16,
col="blue",
lwd=0.1,
frame.plot = F,
xaxt = 'n',
ylim = c(0, 8),
las = 2,
xlim = c(min(A$SNP_pos), max(A$SNP_pos)),
cex.lab=1,
ann = FALSE,
mgp = c(3, 0.8, 0))
I want to plot points representing values from columns "p0.5","p1.5","p2.5",..."p15.5" with 1 color per column, using the points() function from R graphics. In order to obtain 16 colors from a palette called "plasma" I am using the viridis package. To assign 1 color to each column I am using the foreach package.
There are probably simpler ways of doing it, but this is the script I made:
library(foreach)
library(viridis)
INT = seq(0.5,15.5,1)
colID = viridis_pal(option = "plasma")(16)
foreach(k = INT, j = colID) %do% {
INT2 = A$get(paste0("p",k,sep=""))
points(-log10(A$INT2),col=j, pch=19, cex=0.4)
}
However, somehow my script is not recognizing the names of the columns (get(paste0("p",k,sep="")))
Here is a sample from A obtained with dput(A):
structure(list(p0.5 = c(0.242747188094946, 0.168997486361476, 0.107928390753494, 0.00051908418471065, 0.148653246954464, 0.433668277360466, 0.275291500174496, 0.899508301641167, 0.457700101660136, 0.159278241228698, 0.105476048060019, 0.0957898181759544, 0.0262806475294918, 0.20386786083848, 0.0135962839615987, 0.0562814320632579, 0.0761538252424941, 0.11445675670503 ), p1.5 = c(0.0456675606337706, 0.579032583070177, 0.0733987371701725, 0.0125483229728762, 0.0628715045603653, 0.211266478201916, 0.110695151122545, 0.243109951551235, 0.0210778532524462, 0.0493031519980267, 0.0390144011015269, 0.0304772224622842, 0.0084556138719978, 0.0111889644811375, 0.00158950157629228, 0.0899572299188477, 0.117447319097037, 0.0403839701897273), p2.5 = c(0.106205033576986, 0.999008499893865, 0.0000977605223585761, 0.0000222204471434021, 0.0608965716779278, 0.120029817275325, 0.265571691424294, 0.553076531536749, 0.122071577513883, 0.0142361473839313, 0.0140659128442708, 0.0106173904925838, 0.0100709738419846, 0.0220269042478114, 0.0197389283217971, 0.056918781795781, 0.0843907457940626, 0.0065953679321777), p3.5 = c(0.0949379614316481, 0.6576913449417, 0.357953467962908, 0.673495175075545, 0.00356364218471085, 0.00579718014023882, 0.100106211569328, 0.0158453918358466, 0.0969391239180496, 0.0142849538835522, 0.010588950662722, 0.00841341473657932, 0.0107418165679845, 0.00342963776145622, 0.00248045395676769, 0.0256439166722159, 0.0379307961204795, 0.00520668432606975), p4.5 = c(0.0000187175832404615, 0.0449205528979275, 0.454245793136244, 0.625484812568163, 0.00087144135901471, 0.00125393954966476, 0.000495356005020231, 0.00853418997106188, 0.0860658004805283, 0.0138964693607855, 0.00778626888227587, 0.00880374257771237, 0.00992849326319861, 0.00236193358591027, 0.000317125830225305, 0.00270570068269156, 0.00268651630233588, 0.016006809066345), p5.5 = c(0.0297229014556236, 0.450573991501786, 0.538565537374086, 0.199241650260579, 0.140114219338775, 0.298810808152817, 0.457059301374272, 0.000465970378076238, 0.015596915949386, 0.00498096604293199, 0.00180173547360725, 0.00180173547360725, 0.00241248090553604, 0.100258152124521, 0.0347312413053782, 0.0259487420621233, 0.029439670274164, 0.0509346154635958), p6.5 = c(0.00157124564715232, 0.00617602657108606, 0.40323546403784, 0.975963386485613, 0.000498705229682038, 0.00197961640689226, 0.00607507536590394, 0.00475879649921192, 0.0432054681761673, 0.000208405926305886, 0.000124485834074587, 0.000104249584130051, 0.000154505394307958, 0.000466823941774422, 0.00014809982985565, 0.000957049520089973, 0.000907016506181029, 0.000638562546332883 ), p7.5 = c(0.00967614058865758, 0.00611666067998298, 0.344939438378035, 0.829946421184631, 0.0000872148308332329, 0.0010787446205654, 0.00099396409402685, 0.000185220001498869, 0.00445122847464564, 0.0000699305779467999, 0.0000270797969253489, 0.0000395841851201029, 0.0000351568889193048, 0.000308108117176226, 0.0000505880748474765, 0.0000182107980767294, 0.0000307213569343469, 0.0000538257344596745 ), p8.5 = c(0.0298272314697819, 0.00439975455976159, 0.615119474893023, 0.737847234479775, 0.00000260534870255568, 0.0000806900093438783, 0.0000951477742356736, 0.000792707417353214, 0.00612215906548817, 0.00032734137698918, 0.000257161919558846, 0.000372124861505317, 0.000146537968590819, 0.000549732712368789, 0.000418621454407308, 0.000245993613431499, 0.000379405893229818, 0.0000736041041229257 ), p9.5 = c(0.0211527099658549, 0.0000934929361262732, 0.82437218981407, 0.519167449006819, 0.000523156922133462, 0.00258360415905021, 0.00204220285347531, 0.0000154562053722482, 0.00566515791218741, 0.000103533046675889, 0.0000698932530663413, 0.00011717001113944, 0.0000664828013933368, 0.0000997250603534792, 0.000357450389587003, 0.000716062592119114, 0.000846881645964889, 0.000451224448732578 ), p10.5 = c(0.029971421047914, 0.00268695456539587, 0.424557917592327, 0.915046515914916, 0.000568515266303506, 0.00245516212053905, 0.00929053858074703, 0.00415983684212026, 0.0259746272819724, 0.00052532073328366, 0.000590465479955006, 0.00103194578557607, 0.00122815984445129, 0.000698956470929661, 0.00159091618143714, 0.000867824024120008, 0.00124655848935054, 0.000332038074892812 ), p11.5 = c(0.035609130492743, 0.237964075968414, 0.690124238372624, 0.648900366291513, 0.00004710004866214, 0.000275145894207551, 0.00614799286615342, 0.000186840750332432, 0.000914981442505171, 0.165208893610543, 0.115721716938258, 0.13093915642351, 0.118863703039706, 0.0159269747563521, 0.00308345643003936, 0.00862720882125511, 0.0117091662666689, 0.0108686512973407), p12.5 = c(0.00672976815913322, 0.000638938427403905, 0.814337286838706, 0.623969439817503, 0.000807819084297629, 0.00232440718185704, 0.000740458747187747, 0.000728021148772152, 0.0000559657131149375, 0.00978645701481258, 0.0140829048116248, 0.0193192878124661, 0.0498439328612731, 0.00412982514514444, 0.00424479231301975, 0.00196617578444213, 0.00221470494971319, 0.00308388908487704), p13.5 = c(0.0063414607849774, 0.000455425918835152, 0.52835103362498, 0.457946740156627, 0.0151431361797825, 0.0479667906414369, 0.00402089598655567, 0.00408601310637604, 0.00610753504352883, 0.00182377496358575, 0.00180612043092252, 0.00341152291235735, 0.00622315616784477, 0.00136290325730425, 0.00093534946282569, 0.00190275139707705, 0.00264021255779838, 0.00153154541556427 ), p14.5 = c(0.0172886796088735, 0.00262673599171581, 0.75486705783085, 0.861664714579806, 0.00442495915096256, 0.0145607545288462, 0.026313481660887, 0.00338158384879001, 0.00324014806350329, 0.00334338760170889, 0.00336113782656065, 0.00618978341717156, 0.0134855539039173, 0.00131871554558236, 0.000970572324960001, 0.000308088006042178, 0.000485416518092221, 0.00039877284691957), p15.5 = c(0.0129036907113826, 0.000768695252300225, 0.857105484361189, 0.652985460943366, 0.0678412616065989, 0.117470700206561, 0.251848121581743, 0.0266333988671643, 0.0597033572250765, 0.00673143398709981, 0.00578628321608891, 0.00862746246608992, 0.118781559566082, 0.00377416600326799, 0.0416466163677339, 0.0114618669238643, 0.0101411929303934, 0.00439323486043991), SNP_pos = 1:18), .Names = c("p0.5", "p1.5", "p2.5", "p3.5", "p4.5", "p5.5", "p6.5", "p7.5", "p8.5", "p9.5", "p10.5", "p11.5", "p12.5", "p13.5", "p14.5", "p15.5", "SNP_pos"), row.names = c(NA, -18L), class = c("tbl_df", "tbl", "data.frame"))
Please help