How to rotate a Ternary plot in ggtern - r

I have this data collected on a tripole scale, where respondents were clicking on a point inside a triangle to show how someone responded to a situation:
structure(list(ID = c(24262L, 24263L, 24264L, 24266L, 24267L,
24268L, 24269L, 24270L, 24271L, 24272L, 24273L, 24275L, 24279L,
24282L, 24285L, 24286L, 24287L, 24288L, 24290L, 24292L, 24296L,
24298L, 24299L, 24300L, 24301L, 24302L, 24304L, 24305L, 24309L,
24310L, 24314L, 24328L, 24329L, 24330L, 24331L, 24332L, 24333L,
24339L, 24356L, 24363L, 24370L, 24378L, 24388L, 24390L, 24393L,
24404L, 24406L, 24408L, 24410L, 24420L, 24422L, 24431L, 24435L,
24449L, 24456L, 24457L, 24469L, 24503L, 24535L, 24538L, 24541L,
24543L, 24547L, 24549L, 24555L, 24560L, 24562L, 24564L, 24565L,
24574L, 24693L, 24694L, 24707L, 24711L, 24715L, 24717L, 24719L,
24721L, 24723L, 24725L, 24727L, 24733L, 24735L, 24737L, 24742L,
24750L, 24752L, 24758L, 24761L, 24762L, 24764L, 24770L, 24863L,
24865L, 24866L, 24867L, 24870L, 24885L, 24891L, 24984L, 24995L,
25005L, 25006L, 25010L, 25011L, 25012L, 25014L, 25015L, 25091L,
25092L, 25093L, 25094L, 25106L, 25109L, 25110L, 25111L, 25157L,
25159L, 25162L, 25174L, 25176L, 25180L, 25294L, 25295L, 25298L,
25302L, 25303L, 25304L, 25305L, 25308L, 25339L, 25341L, 25343L,
25345L, 25348L, 25349L, 25559L, 25566L, 25573L, 25575L, 25577L,
25579L, 25581L, 25586L, 25614L, 25622L, 25630L, 25631L, 25635L,
25641L, 25670L, 25671L, 25672L, 25673L, 25674L, 25677L, 25684L,
25688L, 25691L, 25693L, 25695L, 25700L, 24211L, 24212L, 24215L,
24217L, 24218L, 24219L, 24220L, 24222L, 24225L, 24226L, 24227L,
24230L, 24232L, 24234L, 24236L, 24237L, 24238L, 24239L, 24240L,
24243L, 24246L, 24247L, 24250L, 24251L, 24252L), Respectfully = c(0.5385952,
0.672799766, 0.515947104, 0.609299839, 0.600087047, 0.215293989,
0.112566531, 0.631413877, 0.171163484, 0.280788928, 0.895692229,
0.247195691, 0.181995317, 0.163163558, 0.900582135, 0.818431854,
0.795888841, 0.614360929, 0.945623696, 0.922643483, 0.628791392,
0.175074518, 0.619624436, 0.595834434, 0.352946192, 0.531283677,
0.211680189, 0.659169912, 0.526771784, 0.929830313, 0.898694217,
0.613898337, 0.617298901, 0.56617099, 0.554916739, 0.64306879,
0.189266831, 0.920095921, 0.712526262, 0.854605317, 0.913350403,
0.933309317, 1.006667733, 0.987369776, 1.017328858, 0.957674563,
0.90463531, 0.9272874, 0.891221881, 0.884747803, 0.933109701,
1.019063711, 0.916044593, 0.156491563, 0.654910684, 0.517636955,
0.247314185, 0.343438685, 0.337267578, 0.326364845, 0.114466496,
0.090442464, 0.243850961, 0.092173956, 0.235721201, 0.996143162,
0.635637045, 0.970861077, 0.948802829, 0.551817477, 0.912414432,
0.200542375, 0.826407254, 0.071805023, 0.892377079, 0.087980591,
0.918832958, 0.099396825, 1.023749948, 0.102644026, 0.107016437,
0.997948647, 0.110704333, 0.940060258, 0.091438882, 0.055989511,
0.081595875, 0.081419758, 0.770171881, 0.610801637, 0.511512518,
1.070922136, 0.593650937, 0.569419086, 0.873148918, 0.378054291,
0.582714975, 0.60744822, 0.14328903, 0.067492828, 0.315115869,
0.75541079, 0.061788347, 0.087719396, 1.049453616, 0.069038175,
1.044347167, 0.501647294, 0.476157516, 0.110015221, 0.269865036,
0.147203833, 0.961993456, 0.785571694, 0.641585886, 0.638352633,
0.609070599, 0.870874465, 0.864675701, 0.096855976, 0.610836565,
0.627459884, 0.874884486, 0.972632468, 0.164256439, 0.873557031,
0.57596755, 0.565361559, 0.586712956, 0.941195965, 0.446302474,
0.206582263, 0.610695481, 0.638060987, 0.530307591, 1.029941678,
0.607028246, 0.6176126, 0.543566525, 0.519073486, 0.609546781,
0.139241472, 0.901534081, 0.150142923, 0.317818969, 0.189081565,
0.626691282, 0.624533534, 0.612181485, 0.634860277, 0.646151781,
0.633498967, 0.624919891, 0.623312056, 0.631034791, 0.608126938,
0.236088231, 0.323942959, 0.919163823, 0.233712777, 0.276786536,
0.833319068, 0.095358528, 0.812533975, 0.209690139, 0.735989869,
0.596592605, 0.493421763, 0.818909705, 0.805246234, 0.613435805,
0.270724922, 0.366894066, 0.600306869, 0.869067788, 0.145871058,
0.604971766, 0.134385094, 0.588236988, 0.587666631, 1.032822847,
0.623843968, 0.605744064, 0.131348848, 0.588236988, 0.087467365,
0.600683391), Transparently = c(0.820800126, 0.615894616, 0.784985006,
0.606558323, 0.842676938, 0.844404042, 0.916779697, 0.615372658,
0.874791503, 0.814765275, 0.126808345, 0.855662525, 0.846717596,
0.862914324, 0.913444817, 0.251324534, 0.248540372, 0.614360929,
0.936769724, 0.095737927, 0.583792984, 0.858672082, 0.603269815,
0.617806852, 0.728860557, 0.763061166, 0.811132908, 0.599038482,
0.811664104, 0.077664897, 0.134824425, 0.606615484, 0.564655364,
0.618685603, 0.633455515, 0.545877218, 0.855959177, 0.095988706,
0.433236271, 0.697069466, 0.932611644, 0.942195773, 1.008322001,
0.992420793, 1.028732777, 0.969780326, 0.122604199, 0.099307142,
0.138839573, 0.150925994, 0.085792698, 1.020697951, 0.095590822,
0.849863172, 0.647231042, 0.773270965, 0.79933852, 0.781846166,
0.777013123, 0.73322922, 0.914041042, 0.923891008, 0.798273802,
0.938193262, 0.839317203, 0.990858972, 0.590011358, 0.042210646,
0.074093886, 0.548788846, 0.916915476, 0.836126328, 0.575304508,
0.935497701, 0.127815932, 0.920728266, 0.104502067, 0.921889246,
1.03024137, 0.907672346, 0.920933843, 1.002946377, 0.903099537,
0.083944403, 0.922207296, 0.956200302, 0.936974704, 0.937197804,
0.270489872, 0.625058591, 0.496246278, 1.073989391, 0.593650937,
0.592372119, 0.694542348, 0.625950456, 0.619678259, 0.570666313,
0.871415496, 0.946574152, 0.728291929, 0.722327173, 0.946510434,
0.926541567, 1.049453616, 0.943204463, 1.03007555, 0.50816232,
0.835366428, 0.918267071, 0.787079275, 0.868908703, 0.951541662,
0.811538815, 0.61506027, 0.663948357, 0.586418152, 0.898504972,
0.1523799, 0.914196193, 0.583227396, 0.606079459, 0.213126272,
0.986245692, 0.870046079, 0.869732857, 0.604211867, 0.736863017,
0.648767114, 0.939423501, 0.557043076, 0.804438114, 0.532972872,
0.598525584, 0.841363668, 1.029941678, 0.612435043, 0.615830719,
0.509812713, 0.497207224, 0.609743237, 0.897805572, 0.863769054,
0.864284277, 0.756386161, 0.861637115, 0.617861569, 0.612092674,
0.622858763, 0.583585918, 0.614777744, 0.603289545, 0.619621992,
0.586993933, 0.593338847, 0.614418983, 0.779004991, 0.70745641,
0.11726483, 0.775427818, 0.74606353, 0.851781547, 0.919092059,
0.924776435, 0.829707384, 0.580720782, 0.596592605, 0.519732594,
0.421046019, 0.215226546, 0.556450188, 0.759358466, 0.824817002,
0.577669203, 0.169151321, 0.881558836, 0.599436522, 0.90624404,
0.604998171, 0.622988939, 1.034414053, 0.626509905, 0.632660449,
0.89102143, 0.604998171, 0.918262541, 0.55049324), Impartially = c(0.465658277,
0.461714715, 0.497125953, 0.520229161, 0.401690006, 0.802266479,
0.894968808, 0.493858635, 0.84177649, 0.737350881, 0.889409304,
0.759607494, 0.847863555, 0.862213612, 0.109956756, 0.771663547,
0.793201268, 0.509038925, 0.069157727, 0.914556921, 0.524168909,
0.847581744, 0.51422137, 0.522430778, 0.704787254, 0.489853799,
0.838132501, 0.486388475, 0.479211062, 0.93793416, 0.875783682,
0.516177416, 0.552293181, 0.549585342, 0.547982574, 0.549040437,
0.829416931, 0.916274369, 0.618573725, 0.305697709, 0.092083447,
0.073197983, 0.008801615, 0.012722424, 0.028896471, 0.043793023,
0.888742805, 0.90670836, 0.875128031, 0.862690747, 0.92150861,
0.02294177, 0.92108041, 0.896055102, 0.44906044, 0.499450028,
0.791781664, 0.680421829, 0.690234244, 0.738181829, 0.893988132,
0.921715975, 0.798098445, 0.910879731, 0.779454529, 0.009174875,
0.512821853, 0.95919919, 0.92872417, 0.63617301, 0.100211762,
0.828822911, 0.428452343, 0.941970348, 0.890839458, 0.929689884,
0.904637277, 0.909784257, 0.031725951, 0.918267727, 0.899998665,
0.005025526, 0.908758759, 0.920179784, 0.921686828, 0.948506773,
0.924896836, 0.925002098, 0.785541952, 0.503044903, 0.803664029,
0.082803823, 0.545991898, 0.570557058, 0.305972755, 0.83199054,
0.532894731, 0.555229306, 0.887567461, 0.938506544, 0.761560678,
0.323256642, 0.947489619, 0.923677325, 0.0566625, 0.938717306,
0.045118894, 0.795827687, 0.525770962, 0.897508681, 0.769734502,
0.883341014, 0.051330354, 0.244468406, 0.485932499, 0.449341804,
0.538715363, 0.138629705, 0.879033506, 0.920966506, 0.540138841,
0.505164027, 0.791890979, 0.027370578, 0.854349852, 0.15208894,
0.553023458, 0.468633413, 0.50540942, 0.069690846, 0.827210844,
0.861133993, 0.591059625, 0.50319165, 0.470964789, 0.034407794,
0.517081559, 0.504993081, 0.700809896, 0.775536239, 0.517217338,
0.870460451, 0.143105969, 0.883978724, 0.728849649, 0.826070011,
0.495627373, 0.502366483, 0.503692865, 0.519353449, 0.482581139,
0.50265485, 0.495607883, 0.525813699, 0.513563395, 0.514401138,
0.839320302, 0.775061905, 0.887907207, 0.853994012, 0.807586253,
0.188630834, 0.918224454, 0.18752791, 0.820726156, 0.454573005,
0.540567636, 0.784800649, 0.584334373, 0.839739561, 0.563928843,
0.798892915, 0.639075577, 0.554966569, 0.848121166, 0.872286737,
0.530407548, 0.872425079, 0.540660083, 0.525467217, 0.038644876,
0.490734726, 0.501179636, 0.886452258, 0.540660083, 0.93474859,
0.581967294)), row.names = c(2L, 3L, 4L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 16L, 17L, 19L, 20L, 21L, 22L, 24L, 25L, 27L,
28L, 29L, 30L, 31L, 32L, 34L, 35L, 37L, 38L, 39L, 40L, 41L, 42L,
43L, 44L, 45L, 51L, 57L, 61L, 65L, 68L, 73L, 74L, 76L, 81L, 82L,
83L, 84L, 88L, 89L, 92L, 93L, 98L, 100L, 101L, 110L, 116L, 121L,
123L, 125L, 126L, 127L, 129L, 130L, 132L, 133L, 134L, 135L, 143L,
146L, 147L, 154L, 157L, 159L, 160L, 161L, 162L, 163L, 164L, 165L,
168L, 169L, 170L, 173L, 177L, 178L, 180L, 181L, 182L, 183L, 186L,
188L, 190L, 191L, 192L, 195L, 196L, 201L, 209L, 213L, 218L, 219L,
222L, 223L, 224L, 225L, 226L, 233L, 234L, 235L, 236L, 239L, 241L,
242L, 243L, 252L, 253L, 256L, 265L, 267L, 270L, 277L, 278L, 281L,
282L, 283L, 284L, 285L, 288L, 294L, 295L, 296L, 297L, 299L, 300L,
303L, 308L, 313L, 314L, 315L, 316L, 317L, 320L, 333L, 337L, 339L,
340L, 343L, 347L, 351L, 352L, 353L, 354L, 355L, 357L, 358L, 360L,
361L, 362L, 363L, 364L, 367L, 368L, 371L, 373L, 374L, 375L, 376L,
378L, 380L, 381L, 382L, 385L, 387L, 389L, 391L, 392L, 393L, 394L,
395L, 396L, 398L, 399L, 401L, 402L, 403L), class = "data.frame")
and would like to create a ternary plot as this one:
So far, I have this code:
plot <- ggtern(data=behavior,aes(x=Respectfully,
z=Transparently,
y=Impartially)) +
geom_point(size=3,fill="yellow",color="red",shape=21)
plot
which gives me this:
How do I rotate the triangle canvas to fit the plot?.
I have searched and could not find any help online.
I don't want to rotate the whole diagram, just the triangle. I want to retain the points as they are.

You can rotate the diagram by an angle (in degrees or radians) using theme_rotate.
library(ggtern)
plot <- ggtern(data=behavior,aes(x=Impartially,
z=Transparently,
y=Respectfully)) +
geom_point(size=3, fill="yellow", color="red", shape=21) +
theme_rotate()
plot

Related

Replace row names with the column value of another data frame based on column matches

I want to replace the row names of meth.kirp.cpg with anno$V1 if the existing row names matches anno$V2.
library(tidyverse)
rownames(meth.kirp.cpg) <- meth.kirp.cpg %>%
rowwise() %>%
mutate(out = anno$V1[str_which(colnames(meth.kirp.cpg), anno$V2)])
Traceback:
Error in `mutate()`:
ℹ In argument: `out = anno$V1[str_which(rownames(meth.kirp.cpg),
anno$V2)]`.
ℹ In row 1.
Caused by error in `str_detect()`:
! Can't recycle `string` (size 142513) to match `pattern` (size 365860).
Run `rlang::last_error()` to see where the error occurred.
Example data:
meth.kirp.cpg
> dput(meth.kirp.cpg[1:100,1:2])
structure(list(TCGA.2K.A9WE.01A = c(0.461440642939772, 0.143910373119058,
0.847164847154162, 0.737361955793681, 0.716794733144112, 0.351877113536983,
0.248986769373366, 0.0121360989202765, 0.876303885229884, 0.944311384947134,
0.0490407302658151, 0.0200484962577958, 0.0623434271852525, 0.489865398138095,
0.920994933496615, 0.92663932531651, 0.0149191766670711, 0.884749685210921,
0.446591784140497, 0.91113228700911, 0.912199953863369, 0.908167409366654,
0.386721526377863, 0.0386737340626713, 0.0347492896507038, 0.98309370597552,
0.0176080612232509, 0.91878387167279, 0.743683318738873, 0.939148492241393,
0.722471943330892, 0.613143449419421, 0.0111202783577944, 0.843823786705695,
0.836431557867031, 0.390282953982417, 0.027408710286304, 0.0222349236137297,
0.657221610108816, 0.861848830221141, 0.0433751011272091, 0.0281247935879252,
0.938960776959358, 0.919825831744144, 0.922071582222369, 0.874732275907705,
0.0287898761495033, 0.0266947996996682, 0.922915821025777, 0.95009866012662,
0.964858875373814, 0.106451342824246, 0.406100902807456, 0.0421684244823044,
0.0341277368595181, 0.805451068725895, 0.147595746750675, 0.602617067494429,
0.90660866745333, 0.922313274809095, 0.462291286891102, 0.502857899902497,
0.0292904155423265, 0.835117565787527, 0.146789494933407, 0.06805696389495,
0.970563583145203, 0.0379479981289824, 0.058526761439653, 0.938993650169269,
0.44761099556807, 0.558961729061086, 0.939778576056268, 0.0728795533192928,
0.812084345787681, 0.899377654465699, 0.940111049552295, 0.838186810388758,
0.715121288990262, 0.897506380407565, 0.0929678061732199, 0.99024632582796,
0.055583745670494, 0.835146654988372, 0.973309086845447, 0.651216797099359,
0.0218535991986461, 0.0999671036378156, 0.790540668893094, 0.980591855409854,
0.567883806155822, 0.774816434396113, 0.904434807209845, 0.16641097147085,
0.0102686285230525, 0.65243489007093, 0.917594420539083, 0.0147831247626457,
0.844679485594683, 0.65566679452182), TCGA.2Z.A9J1.01A = c(0.595894468074615,
0.0807243779293262, 0.867305510246114, 0.70680600651273, 0.217862460492399,
0.169408257004071, 0.173115013795265, 0.0108902025634162, 0.813866558997356,
0.938576461648791, 0.0426568318037534, 0.0133187057875756, 0.0540543120983417,
0.317547629906197, 0.89911570032979, 0.525131175543627, 0.0152198596492253,
0.586968687135673, 0.49896100615873, 0.946718072906056, 0.859306039060091,
0.91185524112895, 0.28077646371254, 0.0413484993379312, 0.169193526857136,
0.941230054689418, 0.0164701153466769, 0.928402415411224, 0.736184540407898,
0.946288965623826, 0.312150292032857, 0.403171876971832, 0.0091246246912222,
0.535149883791691, 0.801041308364712, 0.171664264695538, 0.022737572168221,
0.0164834707992085, 0.34399568227201, 0.690016503202975, 0.0390842331750004,
0.0270854886242561, 0.888936631403145, 0.911902815624012, 0.858247513475469,
0.877113632682254, 0.0342892379505875, 0.0387268488822914, 0.922299785913074,
0.926130065834329, 0.975692332236198, 0.105415153493416, 0.127593519059119,
0.0540003798276299, 0.030980833881057, 0.914299941557146, 0.0512267439881511,
0.307325891435045, 0.941037265659174, 0.927078967007025, 0.48873418258592,
0.259006924115841, 0.0278764868641079, 0.87768067729952, 0.302640875302654,
0.0706384569300761, 0.968762634771395, 0.0364352674378962, 0.0441231506131831,
0.8307385629478, 0.242575477196221, 0.513439830376976, 0.932449172188782,
0.0526229004254996, 0.81314353054328, 0.778591104943176, 0.95668645045373,
0.453172059602829, 0.250129171963381, 0.863470213940097, 0.0994627135023581,
0.989489689575077, 0.0472116225581592, 0.911407225108748, 0.825189076107663,
0.578029414148402, 0.018058167343065, 0.0855852777154159, 0.819733395638372,
0.988287891473147, 0.255899615791521, 0.643359326354994, 0.491979154678761,
0.0978562004864199, 0.0105671614378101, 0.48897100984416, 0.9024550858788,
0.0131702158217202, 0.81328537816321, 0.85890307119103)), row.names = c("cg00000029",
"cg00000165", "cg00000236", "cg00000289", "cg00000292", "cg00000321",
"cg00000363", "cg00000622", "cg00000658", "cg00000721", "cg00000734",
"cg00000769", "cg00000905", "cg00000924", "cg00000948", "cg00000957",
"cg00001245", "cg00001249", "cg00001261", "cg00001349", "cg00001364",
"cg00001446", "cg00001510", "cg00001582", "cg00001583", "cg00001687",
"cg00001747", "cg00001791", "cg00001809", "cg00001854", "cg00001874",
"cg00002033", "cg00002116", "cg00002145", "cg00002190", "cg00002224",
"cg00002236", "cg00002406", "cg00002426", "cg00002449", "cg00002464",
"cg00002490", "cg00002531", "cg00002591", "cg00002593", "cg00002597",
"cg00002660", "cg00002719", "cg00002769", "cg00002808", "cg00002809",
"cg00002810", "cg00002837", "cg00003091", "cg00003173", "cg00003181",
"cg00003287", "cg00003345", "cg00003513", "cg00003529", "cg00003578",
"cg00003625", "cg00003784", "cg00003969", "cg00003994", "cg00004055",
"cg00004067", "cg00004072", "cg00004082", "cg00004089", "cg00004105",
"cg00004121", "cg00004192", "cg00004207", "cg00004209", "cg00004429",
"cg00004533", "cg00004562", "cg00004608", "cg00004773", "cg00004818",
"cg00004883", "cg00004939", "cg00004963", "cg00004979", "cg00004996",
"cg00005010", "cg00005040", "cg00005072", "cg00005083", "cg00005112",
"cg00005166", "cg00005215", "cg00005297", "cg00005306", "cg00005390",
"cg00005437", "cg00005543", "cg00005617", "cg00005619"), class = "data.frame")
anno
> dput(anno[1:100,])
structure(list(V1 = c("TSPY4", "TTTY14", "TMSB4Y", "TBL1Y", "TMSB4Y",
"TSPY4", "RPS4Y2", "EIF1AY", "PCDH11Y", "TBL1Y", "ZFY", "FAM197Y2",
"TTTY14", "TSPY4", "ZFY", "NLGN4Y", "EIF1AY", "TSPY4", "TBL1Y",
"UTY", "PRKY", "ZFY", "CD24", "PRKY", "TSPY1", "CYorf15A", "TSPY2",
"TTTY15", "RPS4Y2", "UTY", "CYorf15A", "RPS4Y2", "TSPY2", "TBL1Y",
"TSPY3", "DDX3Y", "CYorf15A", "ZFY", "RBMY1F", "DDX3Y", "RPS4Y2",
"ZFY", "DDX3Y", "TTTY15", "BCORL2", "PCDH11Y", "KDM5D", "TTTY14",
"EIF1AY", "DDX3Y", "LOC100101121", "CYorf15A", "TTTY15", "TSPY1",
"TSPY1", "FAM197Y2", "TSPY4", "TMSB4Y", "DDX3Y", "TTTY15", "TTTY20",
"NLGN4Y", "TSPY4", "CYorf15A", "RPS4Y2", "KDM5D", "RBMY1J", "EIF1AY",
"KDM5D", "ZFY", "TGIF2LY", "HMGN5", "EBP", "UBL4A", "WDR13",
"MTM1", "BCOR", "ZCCHC12", "FTHL17", "PORCN", "NAA10", "PCDH11X",
"ARSE", "DOCK11", "PDK3", "LONRF3", "MAGIX", "PCYT1B", "SLC6A8",
"UBE2A", "TAF9B", "STARD8", "BCOR", "ZIC3", "IL1RAPL2", "TMSB4X",
"CLCN5", "LOC100133957", "SCML1", "GNL3L"), V2 = c("cg00050873",
"cg00212031", "cg00214611", "cg01707559", "cg02004872", "cg02011394",
"cg02050847", "cg02233190", "cg02494853", "cg02839557", "cg02842889",
"cg03052502", "cg03244189", "cg03443143", "cg03683899", "cg03706273",
"cg03750315", "cg04016144", "cg04042030", "cg04448376", "cg04689676",
"cg04840163", "cg05230942", "cg05480730", "cg05544622", "cg05621349",
"cg05865243", "cg05890011", "cg06322277", "cg06479204", "cg07731488",
"cg07747963", "cg08242338", "cg08921682", "cg09350919", "cg09856092",
"cg10076560", "cg10213302", "cg10267609", "cg10698069", "cg10841270",
"cg11131351", "cg14180491", "cg14741114", "cg15027426", "cg15295597",
"cg15329860", "cg15345074", "cg15422579", "cg15429127", "cg15682806",
"cg15682993", "cg15746461", "cg15810474", "cg15935877", "cg17834650",
"cg17837162", "cg18032798", "cg18077436", "cg25032547", "cg25071634",
"cg25518695", "cg25705492", "cg25756647", "cg26058907", "cg26517491",
"cg26983430", "cg26983535", "cg27049643", "cg27433982", "cg27539833",
"cg00008945", "cg00011200", "cg00011891", "cg00014152", "cg00016522",
"cg00016934", "cg00018261", "cg00021786", "cg00026186", "cg00072288",
"cg00072839", "cg00074638", "cg00112256", "cg00114625", "cg00114913",
"cg00116709", "cg00139317", "cg00140085", "cg00142683", "cg00192980",
"cg00200463", "cg00206414", "cg00240113", "cg00241296", "cg00241907",
"cg00264378", "cg00265812", "cg00266918", "cg00360365")), row.names = c(1L,
2L, 4L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 16L, 17L, 18L,
20L, 21L, 23L, 25L, 27L, 29L, 31L, 34L, 35L, 36L, 37L, 38L, 39L,
40L, 41L, 42L, 43L, 45L, 47L, 48L, 50L, 51L, 52L, 54L, 56L, 57L,
58L, 61L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 72L, 73L, 74L, 75L,
76L, 77L, 78L, 79L, 80L, 82L, 83L, 85L, 86L, 87L, 88L, 89L, 91L,
92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L,
104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L,
115L, 116L, 117L, 118L, 119L, 120L, 122L, 123L, 124L, 125L), class = "data.frame")
There is no match between your cpg dataframe and annotation dataframe:
table(rownames(meth.kirp.cpg) %in% anno$V2)
# FALSE
# 100
Below should work with your full data, assuming there is are no duplicates and all rownames are in annotation dataframe:
rownames(meth.kirp.cpg) <- anno$V2[ match(rownames(meth.kirp.cpg), anno$V2) ]

R: Loop through columns in tibble to find differences between each and create new for each difference

I have been working on this for a while now, but I can't seem to figure it out. I'm looking for a solution that can: calculate difference between col1 and col2 and create colA based on this; then calculate difference between col2 and col3 and create colB based on this, etc. etc. I have about 70 rows and 42 of these columns so it's not something I want to do by hand (at this point I am almost desperate enough).
To give a note also, some of the cells in the rows are empty (NA). An emergency solution would be to fill these with zeroes, but I'd rather not.
Also, the dataframe I use is a tibble, however, I am not bound to this so much that I can't change it to a real dataframe.
My data looks like this:
testdata
As you can see, the columns have annoyingly long names I did not know how to change also :). I use the column numbers usually, which are 77:119. I hope this is complete enough. Sorry for the noob-ness and possibly unclear explanation, this is my first question on here and I'm not that craftsy in R!
Finally, to create the 'user/intermittent_answers/n_length' columns I used the following loop, so I thought it'd be possible to reuse this for the calculations that I need now.
#loop through PARTS of testdata to create _length's
for(i in names(testdata[34:76]))
testdata[[paste(i, 'length', sep="_")]] <- str_length(testdata[[i]])
Then I tried something similar which I found here: FOR loop to calculate difference on dates in R
for (j in 2:length(testdata$`user/intermittant_answers/42_length`))
+ testdata$lag[j] <- as.numeric(difftime(testdata$`user/intermittant_answers/42_length`[j], testdata$`user/intermittant_answers/42_length`[j-1], units=c("difference")), units = "days")
Error in as.POSIXct.numeric(time1) : 'origin' must be supplied
I figured this was because I am not working with anything time related, but I don't know/don't know how to find another 'diff' related function that is not bound to matrixes like the one from matrixStats package.
I hope someone can push me in the right direction!
Thank you!!
EDIT: #Ben, thank you for responding! If I had known this function I would've used it way sooner :'). I tried to keep a representation of NA values inside the df. Also, some people suggested using a double loop, however, I have not managed to figure this out. I hope this helps!
> dput(testdata[1:10, 95:105])
structure(list(`user/intermittant_answers/18_length` = c(NA,
24L, 34L, 33L, NA, NA, 16L, NA, 25L, 28L), `user/intermittant_answers/19_length` = c(NA,
38L, 68L, 34L, NA, 11L, 20L, 12L, 47L, 52L), `user/intermittant_answers/20_length` = c(NA,
59L, 81L, 42L, 2L, 33L, 20L, 26L, 96L, 78L), `user/intermittant_answers/21_length` = c(6L,
90L, 116L, 42L, 14L, 41L, 20L, NA, 127L, 113L), `user/intermittant_answers/22_length` = c(17L,
115L, 131L, 65L, 20L, 70L, 37L, 11L, 170L, 130L), `user/intermittant_answers/23_length` = c(40L,
138L, 188L, 65L, 38L, 113L, 22L, 24L, 200L, 136L), `user/intermittant_answers/24_length` = c(66L,
155L, 210L, 99L, 49L, 133L, 41L, 49L, 242L, 185L), `user/intermittant_answers/25_length` = c(66L,
158L, 233L, 99L, 65L, 156L, 67L, 70L, 296L, 224L), `user/intermittant_answers/26_length` = c(84L,
201L, 250L, 113L, 84L, 164L, 67L, 78L, 334L, 224L), `user/intermittant_answers/27_length` = c(89L,
237L, 285L, 130L, 97L, 167L, 84L, 86L, 412L, 232L), `user/intermittant_answers/28_length` = c(116L,
284L, 315L, 130L, 97L, 184L, 97L, 108L, 445L, 247L)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))

Which apply function in R to use for my calculations

I have a dataframe where each row in the data represents a matchup in a soccer game. Here is a summary with some columns removed, and only for 50 games of a season:
dput(mydata)
structure(list(home_id = c(75L, 323L, 607L, 3627L, 3645L, 641L,
204L, 111L, 287L, 179L, 1062L, 292L, 413L, 275L, 182L, 3639L,
179L, 2649L, 111L, 478L, 383L, 3645L, 275L, 577L, 3639L, 75L,
413L, 287L, 607L, 3627L, 1062L, 75L, 583L, 323L, 3736L, 577L,
179L, 287L, 275L, 3645L, 3639L, 583L, 179L, 413L, 641L, 204L,
478L, 292L, 607L, 323L), away_id = c(3645L, 3736L, 583L, 2649L,
577L, 75L, 3736L, 182L, 323L, 607L, 3639L, 583L, 478L, 383L,
3645L, 607L, 413L, 204L, 641L, 583L, 3627L, 179L, 182L, 3736L,
292L, 204L, 323L, 1062L, 2649L, 3639L, 204L, 292L, 111L, 607L,
182L, 3645L, 478L, 413L, 641L, 287L, 577L, 182L, 2649L, 1062L,
383L, 111L, 3736L, 3627L, 75L, 275L), home_rating = c(1546.64167937943,
1534.94287021653, 1514.51852002403, 1558.91823781777, 1555.76784458784,
1518.37707748967, 1464.5264202735, 1642.57388443639, 1447.37725553409,
1420.69724095008, 1428.51535356064, 1512.81896541907, 1463.29314217469,
1492.70306452585, 1404.65235407107, 1418.03767059747, 1420.69724095008,
1532.76811278441, 1642.57388443639, 1515.31896572792, 1498.7997953168,
1555.76784458784, 1492.70306452585, 1519.94395373088, 1418.03767059747,
1546.64167937943, 1463.29314217469, 1447.37725553409, 1514.51852002403,
1558.91823781777, 1428.51535356064, 1546.64167937943, 1524.71735294388,
1534.94287021653, 1484.09023843799, 1519.94395373088, 1420.69724095008,
1447.37725553409, 1492.70306452585, 1555.76784458784, 1418.03767059747,
1524.71735294388, 1420.69724095008, 1463.29314217469, 1518.37707748967,
1464.5264202735, 1515.31896572792, 1512.81896541907, 1514.51852002403,
1534.94287021653), away_rating = c(1555.76784458784, 1484.09023843799,
1524.71735294388, 1532.76811278441, 1519.94395373088, 1546.64167937943,
1484.09023843799, 1404.65235407107, 1534.94287021653, 1514.51852002403,
1418.03767059747, 1524.71735294388, 1515.31896572792, 1498.7997953168,
1555.76784458784, 1514.51852002403, 1463.29314217469, 1464.5264202735,
1518.37707748967, 1524.71735294388, 1558.91823781777, 1420.69724095008,
1404.65235407107, 1484.09023843799, 1512.81896541907, 1464.5264202735,
1534.94287021653, 1428.51535356064, 1532.76811278441, 1418.03767059747,
1464.5264202735, 1512.81896541907, 1642.57388443639, 1514.51852002403,
1404.65235407107, 1555.76784458784, 1515.31896572792, 1463.29314217469,
1518.37707748967, 1447.37725553409, 1519.94395373088, 1404.65235407107,
1532.76811278441, 1428.51535356064, 1498.7997953168, 1642.57388443639,
1484.09023843799, 1558.91823781777, 1546.64167937943, 1492.70306452585
)), .Names = c("home_id", "away_id", "home_rating", "away_rating"
), row.names = c(NA, 50L), class = "data.frame")
Heres what it looks like:
> head(mydata)
home_id away_id home_rating away_rating
1 75 3645 1546.642 1555.768
2 323 3736 1534.943 1484.090
3 607 583 1514.519 1524.717
4 3627 2649 1558.918 1532.768
5 3645 577 1555.768 1519.944
6 641 75 1518.377 1546.642
The columns home_rating and away_rating are scores that reflect how good each team is, and I'd like to use these columns in an apply function. In particular, I have another function named use_ratings() that looks like this:
# takes a rating from home and away team, as well as is_cup boolean, returns score
use_ratings <- function(home_rating, away_rating, is_cup = FALSE) {
if(is_cup) { # if is_cup, its a neutral site game
rating_diff <- -(home_rating - away_rating) / 400
} else {
rating_diff <- -(home_rating + 85 - away_rating) / 400
}
W_e <- 1 / (10^(rating_diff) + 1)
return(W_e)
}
I'd like to apply this function over every row my mydata, using the values in the home_rating and away_rating column as the parameters passed each time to use_ratings(). How can I do this, thanks?
#SymbolixAU is absolutely right in that the best way to do this (in terms of both speed and readability) is taking advantage of vectorization directly. But if you were to use an "apply function", that function would probably be mapply() or apply():
Using mapply():
mapply(use_ratings, home_rating = mydata$home_rating,
away_rating = mydata$away_rating, is_cup = <a vector of booleans>)
Using apply():
apply(mydata, 1, function(row), use_ratings(row$home_rating, row$away_rating, <row$is_cup, which is missing>)
Multivariate apply (mapply) simultaneously applies a multivariate function to several objects corresponding to its arguments. apply applies a functions over the margins of matrix-like object. Setting MARGIN=1 asks apply to operate on rows. Hence, we had to modify the function to operate on rows and feed the relevant arguments to use_ratings.

Trouble with date column in R (time series)

Hi I am working with a table in r. The first column consists of the date(monthly) and the following columns contain different return data on several portfolios. I downloaded the package PerformanceAnalytics and therefore I need this data to be read a time series.
This is what I tried to do. It has worked with a sheet before. But now I always get this error. But I only changed the return data nothing else. I dont understand why it wont read the date correctly.
> library(PerformanceAnalytics)
Loading required package: xts
Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
Package PerformanceAnalytics (1.4.3541) loaded.
Copyright (c) 2004-2014 Peter Carl and Brian G. Peterson, GPL-2 | GPL-3
http://r-forge.r-project.org/projects/returnanalytics/
> #load file into R
> FactorR <- read.table("~/Desktop/Rfiles/FactorRegression.csv",header=TRUE,sep=";")
>
> #Time Series (first column date)
> FactorR_xts <- xts(x = FactorR[, -1],order.by = as.Date(FactorR$Date))
Error in charToDate(x) :
character string is not in a standard unambiguous format
I attached the dput function so you can see what kind of data I am talking about.(I did not include all data because it would be too much)
put(FactorR)
structure(list(Date = structure(c(203L, 55L, 5L, 142L, 70L, 35L,
85L, 167L, 178L, 102L, 105L, 116L, 204L, 26L, 2L, 143L, 71L,
9L, 145L, 36L, 157L, 169L, 19L, 181L, 107L, 192L, 122L, 7L,
30L, 60L, 146L, 17L, 158L, 90L, 92L, 182L, 49L, 193L, 123L, 8L,
133L, 61L, 72L, 76L, 159L, 41L, 93L, 183L, 22L, 194L, 53L, 3L,
134L, 62L, 147L, 77L, 87L, 170L, 94L, 46L, 108L, 195L, 124L,
9L, 135L, 32L, 148L, 78L, 39L, 171L, 95L, 184L, 109L, 118L, 125L,
10L, 136L, 16L, 149L, 79L, 160L, 172L, 45L, 185L, 110L, 52L,
126L, 11L, 57L, 63L, 150L, 37L, 161L, 173L, 20L, 186L, 111L,
196L, 127L, 28L, 137L, 64L, 73L, 80L, 162L, 42L, 96L, 187L, 23L,
197L, 54L, 4L, 138L, 65L, 34L, 81L, 163L, 174L, 97L, 104L, 112L,
198L, 25L, 1L, 139L, 66L, 151L, 82L, 88L, 175L, 98L, 47L, 113L,
199L, 128L, 12L, 140L, 33L, 152L, 83L, 40L, 176L, 99L, 188L,
114L, 119L, 129L, 29L, 58L, 67L, 153L, 38L, 164L, 177L, 21L,
189L, 115L, 200L, 130L, 13L, 31L, 68L, 154L, 18L, 165L, 91L,
100L, 190L, 50L, 201L, 131L, 14L, 141L, 69L, 74L, 84L, 166L,
43L, 101L, 191L, 24L, 202L), .Label = c("26.02.10", "26.02.99",
"27.02.04", "27.02.09", "27.02.98", "28.02.01", "28.02.02", "28.02.03",
"28.02.05", "28.02.06", "28.02.07", "28.02.11", "28.02.13", "28.02.14",
"28.04.00", "28.04.06", "28.06.02", "28.06.13", "28.09.01", "28.09.07",
"28.09.12", "28.11.03", "28.11.08", "28.11.14", "29.01.10", "29.01.99",
"29.02.00", "29.02.08", "29.02.12", "29.03.02", "29.03.13", "29.04.05",
"29.04.11", "29.05.09", "29.05.98", "29.06.01", "29.06.07", "29.06.12",
"29.07.05", "29.07.11", "29.08.03", "29.08.08", "29.08.14", "29.09.00",
"29.09.06", "29.10.04", "29.10.10", "29.10.99", "29.11.02", "29.11.13",
"29.12.00", "29.12.06", "30.01.04", "30.01.09", "30.01.98", "30.03.01",
"30.03.07", "30.03.12", "30.04.01", "30.04.02", "30.04.03", "30.04.04",
"30.04.07", "30.04.08", "30.04.09", "30.04.10", "30.04.12", "30.04.13",
"30.04.14", "30.04.98", "30.04.99", "30.05.03", "30.05.08", "30.05.14",
"30.06.00", "30.06.03", "30.06.04", "30.06.05", "30.06.06", "30.06.08",
"30.06.09", "30.06.10", "30.06.11", "30.06.14", "30.06.98", "30.06.99",
"30.07.04", "30.07.10", "30.07.99", "30.08.02", "30.08.13", "30.09.02",
"30.09.03", "30.09.04", "30.09.05", "30.09.08", "30.09.09", "30.09.10",
"30.09.11", "30.09.13", "30.09.14", "30.09.98", "30.09.99", "30.10.09",
"30.10.98", "30.11.00", "30.11.01", "30.11.04", "30.11.05", "30.11.06",
"30.11.07", "30.11.09", "30.11.10", "30.11.11", "30.11.12", "30.11.98",
"30.11.99", "30.12.05", "30.12.11", "31.01.00", "31.01.01", "31.01.02",
"31.01.03", "31.01.05", "31.01.06", "31.01.07", "31.01.08", "31.01.11",
"31.01.12", "31.01.13", "31.01.14", "31.03.00", "31.03.03", "31.03.04",
"31.03.05", "31.03.06", "31.03.08", "31.03.09", "31.03.10", "31.03.11",
"31.03.14", "31.03.98", "31.03.99", "31.05.00", "31.05.01", "31.05.02",
"31.05.04", "31.05.05", "31.05.06", "31.05.07", "31.05.10", "31.05.11",
"31.05.12", "31.05.13", "31.05.99", "31.07.00", "31.07.01", "31.07.02",
"31.07.03", "31.07.06", "31.07.07", "31.07.08", "31.07.09", "31.07.12",
"31.07.13", "31.07.14", "31.07.98", "31.08.00", "31.08.01", "31.08.04",
"31.08.05", "31.08.06", "31.08.07", "31.08.09", "31.08.10", "31.08.11",
"31.08.12", "31.08.98", "31.08.99", "31.10.00", "31.10.01", "31.10.02",
"31.10.03", "31.10.05", "31.10.06", "31.10.07", "31.10.08", "31.10.11",
"31.10.12", "31.10.13", "31.10.14", "31.12.01", "31.12.02", "31.12.03",
"31.12.04", "31.12.07", "31.12.08", "31.12.09", "31.12.10", "31.12.12",
"31.12.13", "31.12.14", "31.12.97", "31.12.98", "31.12.99"), class = "factor"),
T1V = c(2.647778077, 2.210168532, 5.184543047, 8.040141376,
1.375197787, 5.254693278, 0.238583717, -0.897572167, -6.812178155,
-4.904778447, 1.445454477, 4.362544312, 0.577758687, -1.049345994,
-0.862978469, 1.496311077, 1.535298083, 0.288034989, 1.002503645,
-0.677737904, 1.148733333, -0.068879397, -0.933636437, 1.952957927,
0.864593373, 0.69587105, 1.566383785, 0.201725025, 0.108433102,
1.121251221, 0.697840536, -0.341798507, 1.750353464, -0.336236355,
-0.173630687, 0.405227621, 0.407442779, 0.301534209, -0.252288427,
-2.197112455, 0.4182172, 2.417270431, -1.777693712, 0.333608117,
-0.963997684, -6.639419411, 0.258711011, 0.186660625, 1.075364953,
-0.260546877, -0.144517713, 2.614703924, 1.592532166, 0.247679225,
-2.45731793, -4.605964615, -0.051317674, -2.162348318, -2.094287999,
1.053871887, 0.775032852, -2.409925349, -1.24731202, 0.20137383,
2.9796142, 1.18379607, 0.530516718, 0.687770774, 2.425813597,
1.070508498, 1.594988715, 2.577337728, 1.735724627, 4.753962343,
1.817757107, 0.287317513, 2.122250222, 0.509726992, 1.623651005,
-0.629218412, 1.413071621, 1.466153048, -0.032322501, 1.570878067,
2.495539535, 4.669928369, 2.540314459, 1.351671444, -0.511289999,
.
..
....
....
1.637709345, 0.949670725, -0.380310863, -1.434786801, 0.546588731,
-1.680930574, -1.497671033, 2.134405674, 0.189844698), T3R = c(0.440505512,
5.325647834, 8.837385281, 21.10071908, 4.5326005, 6.606732343,
-4.488433652, -1.304513421, -27.57526532, -19.22941607, 13.12560656,
10.95535151, -2.960696646, -1.282931055, -4.047714673, 4.325802659,
13.34806221, -3.940632325, 2.668465326, -2.035239493, 2.265868534,
2.901646772, 1.555938816, 8.725598107, 11.1111256, 15.10307892,
10.71764649, -1.860936247, -3.235221339, -0.718662895, 2.928862379,
1.567574208, 0.098434872, -2.639317291, -4.334738565, -7.662240412,
-1.392672778, -0.249440069, -7.519374824, -12.54244192, 3.211494367,
-1.798924417, -9.750103402, -17.47336517, -13.59092267, -30.85835803,
6.627120118, 13.84521564, 1.224167247, -4.282226202, -3.879824851,
11.0002882, -1.633862571, 0.728697276, -15.20216478, -21.43439457,
-9.173494124, -27.72510655, -1.643806123, 15.30080078, -11.42185815,
-10.86780424, -10.08529262, 0.158622664, 19.07560852, 4.410459583,
6.983702045, 9.726738752, 11.96532368, 0.865241128, 10.52710826,
1.824183803, 0.051281172, 7.643560265, 3.857934445, -4.269747269,
0.193491252, -1.127403274, -1.145642636, -4.336023223, -4.750288798,
1.386568693, -3.058304715, 3.87811701, 6.007778471, 6.972611825,
7.139746344, 4.366307305, -4.231872029, 0.465995363, 3.370806119,
6.055047349, 1.589337466, 6.641594709, -5.834167246, 0.500189653,
3.001936466, 5.665564573, 6.219235151, 4.696735739, 3.597032279,
-6.95415108, -2.658694701, 0.700309545, 3.870252718, 4.059903633,
4.129877722, 2.850231626, 6.026897131, 11.42913672, -1.40600749,
4.68987461, 6.138984252, 0.859683472, -0.783511946, -2.061859604,
-7.537614888, -3.971992672, 2.743416779, -13.26388813, 1.902781239,
-21.73358064, 5.433251961, -6.426065721, 5.500056238, 1.813441355,
-11.11515726, -5.234823589, 2.582946217, -16.67855167, -36.66711169,
-12.46637364, -5.211445441, -8.572591139, -17.88276043, 2.956958358,
25.59635755, 9.043196394, -1.052072638, 8.698101054, 11.55426061,
6.544403365, -4.495701412, -3.156245124, -1.293693294, 5.803543849,
-0.762197087, 8.000348105, 2.646959488, -12.09434448, -2.563082034,
1.466128125, -1.863374559, 4.699135454, 3.622459782, -1.706221195,
4.038651722, 2.817603386, 1.027156327, -1.486388335, 0.168641413,
-3.888501653, -9.915080583, -11.88374941, -13.56634471, -10.51374661,
3.846951996, -11.50943308, 2.074359943, 7.548294859, 6.711539857,
1.806850477, -0.576496993, -9.21065397, -4.154519223, 3.525193617,
-0.24777096, 3.601168094, 0.143557195, -6.368196817, 5.231960646,
6.810400741, 3.672507394, -2.556477674, -2.869519924, 4.479135652,
-5.380429829, 1.713023169, 3.396652152, 4.922622663, 4.040155598,
1.512006061, 0.24907751, 4.496251525, 0.92375895, -0.774870584,
-3.784012139, 5.614058853, 5.327086162, -0.706470295, 0.771043886,
-4.377376587, -2.491251246, 3.172560156, -2.082216546)), .Names = c("Date",
"T1V", "T2V", "T3V", "T1MV", "T2MV", "T3MV", "T1BTM", "T2BTM",
"T3BTM", "T1MOM", "T2MOM", "T3MOM", "Rm", "SMB", "HML", "MOM",
"T1R", "T2R", "T3R"), class = "data.frame", row.names = c(NA,
-205L))
I would be very happy if anyone could help me.
You need to specify your date format (see ?as.Date):
dates <- c("26.02.10", "26.02.99", "27.02.04", "27.02.09", "27.02.98", "28.02.01", "28.02.02", "28.02.03")
as.Date(dates, "%d.%m.%y")

Create barplot R for coverage

I want to create a barplot and my data is in a csv file in the following format
0,22
40,50
80,62
120,70
160,62
200,49
240,52
280,64
320,57
360,50
400,47
440,52
480,73
520,70
560,68
600,71
640,69
680,61
720,59
760,59
800,62
840,62
880,62
920,72
960,81
1000,89
1040,86
1080,76
1120,80
1160,95
The element before the comma should be the position in the x axis and the element after the comma the height= of the bar at that position. I can do this in Excel but the data is large.
The graph I want would look like this.
I have tried the following but I think it sums the data in each row.
data <- as.matrix(read.csv(file="data.csv",sep=",",header=FALSE))
barplot(data)
barplot(x$V2, names.arg = seq_len(nrow(x)), cex.names = .6)
two things: first, if you supply the whole matrix to the height parameter of barplot, it will sum them. instead, give it only your data.
dput(dat)
structure(c(0L, 40L, 80L, 120L, 160L, 200L, 240L, 280L, 320L,
360L, 400L, 440L, 480L, 520L, 560L, 600L, 640L, 680L, 720L, 760L,
800L, 840L, 880L, 920L, 960L, 1000L, 1040L, 1080L, 1120L, 1160L,
22L, 50L, 62L, 70L, 62L, 49L, 52L, 64L, 57L, 50L, 47L, 52L, 73L,
70L, 68L, 71L, 69L, 61L, 59L, 59L, 62L, 62L, 62L, 72L, 81L, 89L,
86L, 76L, 80L, 95L), .Dim = c(30L, 2L), .Dimnames = list(NULL,
c("V1", "V2")))
barplot(height=dat[,2])
second, you need to supply the names.arg to barplot to get the labeling:
barplot(height=dat[,2], names.arg=dat[,1])
a side note: its best to avoid naming variables with built in R functions. ?data is probably the most commonly overwritten! I use dat instead regularly.
Using your method of getting the data into R:
myData <- read.csv(file = "data.csv", sep = ",", header = FALSE)
To make sure that the order of the bars follows the order of the values in the first column (although this is not strictly what you asked for in your question)
myData2 <- myData[order(myData[, 1]), ]
barplot(myData2[, 2], names.arg = myData2[, 1])
For tweaking the graph, I recommend spending some time reading ?barplot and ?par

Resources