warning when running clmm model - r

I am trying to run a clmm to examine the effects of average_Mg, average_Mn, and average_ZN on the response variable (Spawn_ID)
I have two random effects that are added into the model "(1|Time/ID)" (time is nested into ID and each ID has a different number of time because some ID's have more observations than other IDs) (see picture)
BLA14 has time 1-8 while BLA2 has time 1-11
here is my data:
data1 <- structure(list(Spawn_ID = structure(c(1L, 1L, 1L, 2L, 2L, 3L,
3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L,
2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 2L, 3L, 3L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 2L, 3L, 3L,
1L, 1L, 1L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L,
1L, 1L, 2L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L), .Label = c("1",
"2", "3"), class = c("ordered", "factor")), average_Mg = c(0.0841567034686979,
0.00262726492114602, 0.353259164624795, -0.0364882169624394,
0.355390763410209, -0.151476304441742, -0.0936982567875358, 0.162382425722223,
-1.42681140542971, -1.07244649331608, -0.781118702245109, -1.21952099438996,
-1.38524008095868, -0.898983285649544, -1.01088138645042, -1.56153946055641,
-1.21949786511762, -0.887755361220044, -1.28496187594515, -1.82368718501736,
-1.44293956646485, -1.55766693069354, -1.58965315500885, -1.44731801677922,
-1.90014469879122, -1.39433781118039, -1.3954911611769, -0.866262522744268,
-0.893780676281797, -1.13725619637354, -1.50364564206296, -0.845596282408769,
-0.911535321390588, -1.41202503488084, -1.16477711028459, -0.928588557438047,
-1.0717825099406, -1.27071094552779, -0.102981887484371, -0.419552015986426,
0.207549199784127, -0.26688619247063, -0.0285388879140084, -0.104483586190019,
-0.374343912017509, -0.079286617457435, 0.502081027554914, 0.617397464912897,
0.658216645632926, 0.426442596169416, 0.437015933595451, -1.09407187513834,
-0.289722984650423, 0.189585827711078, 0.388488397202216, -0.814972632964376,
0.0191088328270176, -0.0788536189757766, -1.01469763732677, -0.532896761096259,
-0.319455285766885, 0.32814415425849, -1.10320849618017, -0.802227061565149,
-0.540984260212337, -1.14703007008055, -0.482835715257794, -1.23114539323637,
-0.881874890913403, -0.479104993907372, 0.722375571708869, 0.890893182481924,
1.1899980340988, 0.784338248057351, 0.6979419698913, 1.10833467622332,
0.749554401158789, 0.761841531876783, 1.38243732271989, 1.38537086804658,
0.686397638698291, 1.38660240844063, 1.90358175564482, 1.30513882860368,
0.9706833889022, 2.02786238069347, 0.633278771850179, 0.773554195390702,
1.26407209402018, 0.711780226990467, 1.12404623953355, 0.772411304871684,
0.746907192859431, 1.26546029276059, 0.754582077531832, 0.97865102792368,
1.25739249978455, 1.00030371910859, 1.20251423376581, 0.508886239812359,
1.0614400765502, 1.15560112394629, 0.810899892639843, 0.864356170995008,
1.0722853284304, 0.459017471399662, 0.622305015414975, 0.654778017554924,
0.630012469467092, 1.66357555743707, 1.51486425579301, 0.468256912570358,
1.46986769298999, 0.842853031161864, 0.527443923164085, 0.878231897515369,
1.01564664723517, 0.548373164352724, -1.54705977070176, -1.7628880927376,
-1.93886600741023, -1.75280825324115, -1.06329603003556, -1.76583856532739,
-2.03620478132805, -1.37852741943318, 0.491445103158986, 0.579237889782203,
0.581147814257234, 0.587993370694159, 0.673660535135936, 0.773224639425602,
0.472056000685565, 0.803037596940575, 0.686349802316703, 0.67297390357697,
0.877084884098423, 0.116853127650954, 0.633207695175741, 0.475407810726902,
0.410454398351338, 0.761825383439366, 0.049981065597767, 0.352528868363907,
1.08494544768163), average_Mn = c(0.550041395336084, 0.106013801445048,
0.195501740474326, 0.443055327801251, 0.166039412117922, 0.306826485641131,
0.0779488541952551, 0.253041943200378, -0.398175664467298, -0.248653116953824,
1.62701418452763, 2.12294900204613, -0.653505561079324, 1.18649551151282,
1.73706605332464, -0.663237964024895, -0.502022515338005, 1.37488148179862,
1.52730443891077, -1.02791508823558, -0.912000741847277, -1.13836183212639,
-1.0203769070181, -0.944729930532721, -1.08022080193656, -0.798637523498975,
-0.892966674264699, -0.106867747759299, -0.446077807686831, 0.260985129778798,
0.34207999245625, -0.256052324398952, -0.455901687059591, -0.124589605852459,
-0.330899017708168, -0.155941754430574, 0.179724557145222, -0.13333037309261,
-0.467033378092841, -1.02354293597083, -0.324678510862249, -0.780338971498965,
-0.638323663037884, -0.833876759864611, -1.23290374823043, -0.791651926017789,
-0.507461130613381, -0.8368428812325, -0.0557361418099642, -0.804531913988396,
-0.704346938462444, -0.483778753666885, 0.393712753506288, 0.427715184816051,
0.479775271348421, -0.28130811769396, 0.485295306906789, 0.29873238753337,
-0.32311305698219, -0.153688760742991, 0.566586154995381, 0.432231338528875,
1.06596225482086, 1.35634853919191, 3.80694326707882, 0.810475117293976,
3.0387608847462, 0.633718464176746, 1.1751890651466, 3.9845446592986,
-1.37297875557724, -1.09420268685371, -0.962614525736854, -1.29805138281804,
-1.31055976157738, -0.925719147858883, -1.23243978183704, -1.33945462492742,
-0.733417598434015, -0.930363022530595, -1.27774840900127, -0.551645520494324,
1.07748304807901, -0.396816101914801, -0.619403529151145, 0.904015824338447,
-0.287220128038401, -0.413048098445259, 0.612345039773056, 0.12520419272066,
0.144889119165393, -0.376872327860885, -0.371321461123647, 0.713414294431202,
-0.220319649249486, 1.91457944140036, 1.96765430981412, -0.121347747943895,
1.83594114293694, -0.874846076775421, 1.57970089137696, 1.93625153606136,
0.346364402583701, 1.77363591575721, 0.715776292044604, -0.11504600156397,
0.957194866002839, -0.887101387136546, -0.780049232064872, -0.336706490132965,
-0.70438883179631, -0.873817482659086, -0.284434200328209, -0.568305044660584,
-0.775993306095371, -0.771770658609636, -0.383838373137703, -0.811970593682299,
-0.73465457432939, 0.0911351344017551, 1.2707682140586, -0.777318831552788,
1.11134230637355, -0.783796841885501, 0.259370669933754, 1.73241147006831,
-0.725970777900951, -0.438118569726494, -0.278337133147783, -0.493758812846972,
-0.518179622331699, -0.389789488287258, -0.298381997017347, -0.612423478602631,
-0.429659970678406, -0.292999247051666, -0.435183828919258, -0.897633859213429,
0.507974413224703, 1.43201049921323, -0.66047577071763, 0.786340467145023,
-0.95656045144662, -0.132752976801546, 1.18466694854915), average_Zn = c(0.199618761426643,
0.591792310386536, 1.3751346661716, 0.332582639073901, 0.560402369414685,
0.11570820588524, 0.192150397195304, 1.39288706671957, -0.394083581015067,
-0.0798076017654593, 1.17669193020793, 0.607211261125105, -0.452359206037806,
0.771410079352111, 0.494544784665782, -0.625267178823271, -0.39226745167263,
1.16595745311139, 0.395578830413474, -1.34293822466577, -0.742961944779728,
-1.55476909975203, -1.21117698813619, -0.705958753206111, -1.37118754349972,
-0.917928244368175, -0.974434964905969, -1.01929394953207, -1.12532371386981,
-1.22700631035692, -1.46133511017614, -0.952449170432, -1.21027641358059,
-1.3226625940125, -1.16430485224588, -1.08770522025381, -1.18121144700268,
-1.40033431712296, -0.618587673725525, -0.91706750820117, 0.41088121270189,
-0.78430313474907, -0.409059258341318, -0.975516971079657, -1.27140585793008,
-0.198796133331597, -0.429336908924874, -0.0174222425394045,
-0.161004481467468, -0.405810552877399, -0.370285632509627, -0.89866639987887,
1.10645284167993, 1.8809570525936, 1.92254222169752, -0.0950224222539316,
1.58853988090432, 1.78386607934181, -0.817728723571643, 0.459412598781715,
1.423493404365, 1.7768774695448, -1.12006569075839, -0.751966514798299,
-0.488043380249217, -1.11596293893295, 0.273653921626916, -1.30713710349688,
-0.886375551803829, 0.0239199838971528, -1.3593629685693, -0.643843217883837,
-0.281272478019681, -1.30622537314287, -1.33112371265123, -0.909101703993645,
-1.12755493783614, -1.40003719660867, -0.290337728601771, -0.28987232858238,
-1.19056584307422, -0.193624949117038, 0.975332436429838, -0.218160046225909,
-0.132462974128803, 1.39468641578899, -0.302150834825655, -0.107400685186729,
1.125970810338, -0.256092735038377, 0.158506693687128, -0.378339394736207,
-0.349357413758689, 0.803679188551612, -0.146048595417096, -0.286845588476566,
0.158259418849209, -0.323113138916157, 0.108646496285904, -0.771878347558138,
0.0273033684358348, 0.0453235133932348, 1.28361673646552, 1.29073622845612,
1.24630790251793, 0.944986804400661, 0.981991016697687, 1.3473053430083,
0.827378725150942, 2.48208427225106, 2.69830294706435, 1.03039606923181,
2.27492560926846, 1.10744827135352, 1.35324680735362, 1.84388638700427,
1.52873550347441, 1.40071898822651, 0.260928795100606, -1.16734754082697,
-0.878145608518404, -0.00331768573206932, -0.910939824808822,
0.125144947309071, -1.67327192782442, -0.531813491778335, -0.546522958404239,
-0.0196439100156154, 0.0745476695275746, 0.794370508556172, -0.210218336601184,
0.445705743628815, 0.0718198426307307, -0.122444182892431, 0.184211311538213,
0.183194361394073, 1.12410771197491, -0.741883323524288, 0.716760255429898,
1.76025647136123, -0.00419702451761512, 1.25254232235371, -0.880576082155036,
-0.00114985682377106, 1.78721959263295), ID = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L), .Label = c("BLA14",
"BLA2", "BLA20", "BLA209", "BLA21", "BLA211", "BLA238", "BLA24",
"BLA25", "BLA283", "BLA307", "BLA31", "BLA42", "BLA47", "BLA5",
"BLA79", "BLA80"), class = "factor"), Time = structure(c(2L,
5L, 8L, 3L, 6L, 1L, 4L, 7L, 2L, 5L, 8L, 11L, 3L, 6L, 9L, 1L,
4L, 7L, 10L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L, 2L, 5L, 8L, 11L,
3L, 6L, 9L, 1L, 4L, 7L, 10L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L,
2L, 5L, 3L, 1L, 4L, 2L, 5L, 8L, 11L, 3L, 6L, 8L, 1L, 4L, 7L,
10L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L, 5L, 8L, 11L, 2L, 3L, 6L,
9L, 4L, 7L, 10L, 1L, 2L, 5L, 3L, 1L, 4L, 2L, 5L, 8L, 3L, 6L,
1L, 4L, 7L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L, 2L, 5L, 3L, 1L, 4L,
2L, 5L, 8L, 11L, 3L, 6L, 9L, 1L, 4L, 7L, 10L, 2L, 5L, 8L, 3L,
6L, 1L, 4L, 7L, 2L, 5L, 8L, 11L, 3L, 6L, 9L, 1L, 4L, 7L, 10L,
2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L), .Label = c("1", "2", "3", "4",
"5", "6", "7", "8", "9", "10", "11"), class = c("ordered", "factor"
))), class = "data.frame", row.names = c(NA, -145L))
here is my model:
#model
clmm(Spawn_ID ~ average_Mg + average_Mn + average_Zn + (1|ID/Time), data = data1)
warning message
Warning messages:
1: Using formula(x) is deprecated when x is a character vector of length > 1.
Consider formula(paste(x, collapse = " ")) instead.
2: no. random effects (=161) >= no. observations (=145)

Related

Putting nested random effects in polr function

I am trying to run an ordinal logistic regression mixed model with nested random effects using the polr function from package MASS.
average_Mg, average_Mn, and average_Zn are the predictor variables. the response variable is (Spawn_ID)
I have two random effects that are added into the model "(1|Time/ID)" (time is nested into ID and each ID has a different number of time because some ID's have more observations than other IDs) (see picture)
enter image description here
data:
data1 <- structure(list(Spawn_ID = structure(c(1L, 1L, 1L, 2L, 2L, 3L,
3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L,
2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 2L, 3L, 3L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 2L, 3L, 3L,
1L, 1L, 1L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L,
1L, 1L, 2L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L), .Label = c("1",
"2", "3"), class = c("ordered", "factor")), average_Mg = c(0.0841567034686979,
0.00262726492114602, 0.353259164624795, -0.0364882169624394,
0.355390763410209, -0.151476304441742, -0.0936982567875358, 0.162382425722223,
-1.42681140542971, -1.07244649331608, -0.781118702245109, -1.21952099438996,
-1.38524008095868, -0.898983285649544, -1.01088138645042, -1.56153946055641,
-1.21949786511762, -0.887755361220044, -1.28496187594515, -1.82368718501736,
-1.44293956646485, -1.55766693069354, -1.58965315500885, -1.44731801677922,
-1.90014469879122, -1.39433781118039, -1.3954911611769, -0.866262522744268,
-0.893780676281797, -1.13725619637354, -1.50364564206296, -0.845596282408769,
-0.911535321390588, -1.41202503488084, -1.16477711028459, -0.928588557438047,
-1.0717825099406, -1.27071094552779, -0.102981887484371, -0.419552015986426,
0.207549199784127, -0.26688619247063, -0.0285388879140084, -0.104483586190019,
-0.374343912017509, -0.079286617457435, 0.502081027554914, 0.617397464912897,
0.658216645632926, 0.426442596169416, 0.437015933595451, -1.09407187513834,
-0.289722984650423, 0.189585827711078, 0.388488397202216, -0.814972632964376,
0.0191088328270176, -0.0788536189757766, -1.01469763732677, -0.532896761096259,
-0.319455285766885, 0.32814415425849, -1.10320849618017, -0.802227061565149,
-0.540984260212337, -1.14703007008055, -0.482835715257794, -1.23114539323637,
-0.881874890913403, -0.479104993907372, 0.722375571708869, 0.890893182481924,
1.1899980340988, 0.784338248057351, 0.6979419698913, 1.10833467622332,
0.749554401158789, 0.761841531876783, 1.38243732271989, 1.38537086804658,
0.686397638698291, 1.38660240844063, 1.90358175564482, 1.30513882860368,
0.9706833889022, 2.02786238069347, 0.633278771850179, 0.773554195390702,
1.26407209402018, 0.711780226990467, 1.12404623953355, 0.772411304871684,
0.746907192859431, 1.26546029276059, 0.754582077531832, 0.97865102792368,
1.25739249978455, 1.00030371910859, 1.20251423376581, 0.508886239812359,
1.0614400765502, 1.15560112394629, 0.810899892639843, 0.864356170995008,
1.0722853284304, 0.459017471399662, 0.622305015414975, 0.654778017554924,
0.630012469467092, 1.66357555743707, 1.51486425579301, 0.468256912570358,
1.46986769298999, 0.842853031161864, 0.527443923164085, 0.878231897515369,
1.01564664723517, 0.548373164352724, -1.54705977070176, -1.7628880927376,
-1.93886600741023, -1.75280825324115, -1.06329603003556, -1.76583856532739,
-2.03620478132805, -1.37852741943318, 0.491445103158986, 0.579237889782203,
0.581147814257234, 0.587993370694159, 0.673660535135936, 0.773224639425602,
0.472056000685565, 0.803037596940575, 0.686349802316703, 0.67297390357697,
0.877084884098423, 0.116853127650954, 0.633207695175741, 0.475407810726902,
0.410454398351338, 0.761825383439366, 0.049981065597767, 0.352528868363907,
1.08494544768163), average_Mn = c(0.550041395336084, 0.106013801445048,
0.195501740474326, 0.443055327801251, 0.166039412117922, 0.306826485641131,
0.0779488541952551, 0.253041943200378, -0.398175664467298, -0.248653116953824,
1.62701418452763, 2.12294900204613, -0.653505561079324, 1.18649551151282,
1.73706605332464, -0.663237964024895, -0.502022515338005, 1.37488148179862,
1.52730443891077, -1.02791508823558, -0.912000741847277, -1.13836183212639,
-1.0203769070181, -0.944729930532721, -1.08022080193656, -0.798637523498975,
-0.892966674264699, -0.106867747759299, -0.446077807686831, 0.260985129778798,
0.34207999245625, -0.256052324398952, -0.455901687059591, -0.124589605852459,
-0.330899017708168, -0.155941754430574, 0.179724557145222, -0.13333037309261,
-0.467033378092841, -1.02354293597083, -0.324678510862249, -0.780338971498965,
-0.638323663037884, -0.833876759864611, -1.23290374823043, -0.791651926017789,
-0.507461130613381, -0.8368428812325, -0.0557361418099642, -0.804531913988396,
-0.704346938462444, -0.483778753666885, 0.393712753506288, 0.427715184816051,
0.479775271348421, -0.28130811769396, 0.485295306906789, 0.29873238753337,
-0.32311305698219, -0.153688760742991, 0.566586154995381, 0.432231338528875,
1.06596225482086, 1.35634853919191, 3.80694326707882, 0.810475117293976,
3.0387608847462, 0.633718464176746, 1.1751890651466, 3.9845446592986,
-1.37297875557724, -1.09420268685371, -0.962614525736854, -1.29805138281804,
-1.31055976157738, -0.925719147858883, -1.23243978183704, -1.33945462492742,
-0.733417598434015, -0.930363022530595, -1.27774840900127, -0.551645520494324,
1.07748304807901, -0.396816101914801, -0.619403529151145, 0.904015824338447,
-0.287220128038401, -0.413048098445259, 0.612345039773056, 0.12520419272066,
0.144889119165393, -0.376872327860885, -0.371321461123647, 0.713414294431202,
-0.220319649249486, 1.91457944140036, 1.96765430981412, -0.121347747943895,
1.83594114293694, -0.874846076775421, 1.57970089137696, 1.93625153606136,
0.346364402583701, 1.77363591575721, 0.715776292044604, -0.11504600156397,
0.957194866002839, -0.887101387136546, -0.780049232064872, -0.336706490132965,
-0.70438883179631, -0.873817482659086, -0.284434200328209, -0.568305044660584,
-0.775993306095371, -0.771770658609636, -0.383838373137703, -0.811970593682299,
-0.73465457432939, 0.0911351344017551, 1.2707682140586, -0.777318831552788,
1.11134230637355, -0.783796841885501, 0.259370669933754, 1.73241147006831,
-0.725970777900951, -0.438118569726494, -0.278337133147783, -0.493758812846972,
-0.518179622331699, -0.389789488287258, -0.298381997017347, -0.612423478602631,
-0.429659970678406, -0.292999247051666, -0.435183828919258, -0.897633859213429,
0.507974413224703, 1.43201049921323, -0.66047577071763, 0.786340467145023,
-0.95656045144662, -0.132752976801546, 1.18466694854915), average_Zn = c(0.199618761426643,
0.591792310386536, 1.3751346661716, 0.332582639073901, 0.560402369414685,
0.11570820588524, 0.192150397195304, 1.39288706671957, -0.394083581015067,
-0.0798076017654593, 1.17669193020793, 0.607211261125105, -0.452359206037806,
0.771410079352111, 0.494544784665782, -0.625267178823271, -0.39226745167263,
1.16595745311139, 0.395578830413474, -1.34293822466577, -0.742961944779728,
-1.55476909975203, -1.21117698813619, -0.705958753206111, -1.37118754349972,
-0.917928244368175, -0.974434964905969, -1.01929394953207, -1.12532371386981,
-1.22700631035692, -1.46133511017614, -0.952449170432, -1.21027641358059,
-1.3226625940125, -1.16430485224588, -1.08770522025381, -1.18121144700268,
-1.40033431712296, -0.618587673725525, -0.91706750820117, 0.41088121270189,
-0.78430313474907, -0.409059258341318, -0.975516971079657, -1.27140585793008,
-0.198796133331597, -0.429336908924874, -0.0174222425394045,
-0.161004481467468, -0.405810552877399, -0.370285632509627, -0.89866639987887,
1.10645284167993, 1.8809570525936, 1.92254222169752, -0.0950224222539316,
1.58853988090432, 1.78386607934181, -0.817728723571643, 0.459412598781715,
1.423493404365, 1.7768774695448, -1.12006569075839, -0.751966514798299,
-0.488043380249217, -1.11596293893295, 0.273653921626916, -1.30713710349688,
-0.886375551803829, 0.0239199838971528, -1.3593629685693, -0.643843217883837,
-0.281272478019681, -1.30622537314287, -1.33112371265123, -0.909101703993645,
-1.12755493783614, -1.40003719660867, -0.290337728601771, -0.28987232858238,
-1.19056584307422, -0.193624949117038, 0.975332436429838, -0.218160046225909,
-0.132462974128803, 1.39468641578899, -0.302150834825655, -0.107400685186729,
1.125970810338, -0.256092735038377, 0.158506693687128, -0.378339394736207,
-0.349357413758689, 0.803679188551612, -0.146048595417096, -0.286845588476566,
0.158259418849209, -0.323113138916157, 0.108646496285904, -0.771878347558138,
0.0273033684358348, 0.0453235133932348, 1.28361673646552, 1.29073622845612,
1.24630790251793, 0.944986804400661, 0.981991016697687, 1.3473053430083,
0.827378725150942, 2.48208427225106, 2.69830294706435, 1.03039606923181,
2.27492560926846, 1.10744827135352, 1.35324680735362, 1.84388638700427,
1.52873550347441, 1.40071898822651, 0.260928795100606, -1.16734754082697,
-0.878145608518404, -0.00331768573206932, -0.910939824808822,
0.125144947309071, -1.67327192782442, -0.531813491778335, -0.546522958404239,
-0.0196439100156154, 0.0745476695275746, 0.794370508556172, -0.210218336601184,
0.445705743628815, 0.0718198426307307, -0.122444182892431, 0.184211311538213,
0.183194361394073, 1.12410771197491, -0.741883323524288, 0.716760255429898,
1.76025647136123, -0.00419702451761512, 1.25254232235371, -0.880576082155036,
-0.00114985682377106, 1.78721959263295), ID = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L), .Label = c("BLA14",
"BLA2", "BLA20", "BLA209", "BLA21", "BLA211", "BLA238", "BLA24",
"BLA25", "BLA283", "BLA307", "BLA31", "BLA42", "BLA47", "BLA5",
"BLA79", "BLA80"), class = "factor"), Time = structure(c(2L,
5L, 8L, 3L, 6L, 1L, 4L, 7L, 2L, 5L, 8L, 11L, 3L, 6L, 9L, 1L,
4L, 7L, 10L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L, 2L, 5L, 8L, 11L,
3L, 6L, 9L, 1L, 4L, 7L, 10L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L,
2L, 5L, 3L, 1L, 4L, 2L, 5L, 8L, 11L, 3L, 6L, 8L, 1L, 4L, 7L,
10L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L, 5L, 8L, 11L, 2L, 3L, 6L,
9L, 4L, 7L, 10L, 1L, 2L, 5L, 3L, 1L, 4L, 2L, 5L, 8L, 3L, 6L,
1L, 4L, 7L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L, 2L, 5L, 3L, 1L, 4L,
2L, 5L, 8L, 11L, 3L, 6L, 9L, 1L, 4L, 7L, 10L, 2L, 5L, 8L, 3L,
6L, 1L, 4L, 7L, 2L, 5L, 8L, 11L, 3L, 6L, 9L, 1L, 4L, 7L, 10L,
2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L), .Label = c("1", "2", "3", "4",
"5", "6", "7", "8", "9", "10", "11"), class = c("ordered", "factor"
))), class = "data.frame", row.names = c(NA, -145L))
Current code for model
model2<- polr(Spawn_ID ~ average_Mg + average_Mn + average_Zn + (1| ID/Time), data = data1, method = "logistic", Hess = TRUE)
error message
Error in family$linkfun(mustart) :
Argument mu must be a nonempty numeric vector
In addition: Warning messages:
1: In eval(predvars, data, env) :
Incompatible methods ("Ops.factor", "Ops.ordered") for "/"
2: In Ops.factor(1, ID/Time) : ‘|’ not meaningful for factors

R ggplot geom_tile or geom_raster: Interpolate and fill in the gaps on a non-rectangular grid

I'm creating multiple tile/heatmap plots with geom_raster and/or geom_tile. The data are arranged as col (x), row (y), and the z-value is the fill gradient. The pattern has large gaps in it -- a few by missing data but mostly by design -- the data represents a row/column array of a set of measurements on a 2-D circular surface. (Note: this is a subset. The full set of data consists of 27 plots.)
My question is, how do I interpolate to fill in these gaps in these maps to make them appears as continuous surfaces?
My plot code:
library(ggplot2)
ggplot(ex, aes(col, row, fill = z)) +
geom_raster() +
scale_fill_gradient2(low = "blue", high = "red",
mid = "white", midpoint = 0, limits=c(-0.015, 0.015),
labels = scales::percent) +
scale_y_continuous(trans = "reverse") +
facet_wrap(.~as.factor(order)) +
theme_dark()
Data set:
ex <- structure(list(order = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L), row = c(1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L,
4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L,
7L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L,
11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 14L,
14L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L,
5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L,
8L, 8L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L,
11L, 11L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 14L, 14L, 1L, 1L,
2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L,
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 9L, 9L,
9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L,
12L, 12L, 12L, 13L, 13L, 13L, 14L, 14L, 1L, 1L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L,
7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 10L,
10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L,
13L, 13L, 13L, 14L, 14L), col = c(6L, 9L, 5L, 8L, 11L, 4L, 7L,
9L, 10L, 3L, 5L, 6L, 9L, 12L, 2L, 5L, 8L, 11L, 4L, 7L, 10L, 13L,
3L, 6L, 9L, 11L, 12L, 2L, 4L, 5L, 8L, 11L, 4L, 7L, 10L, 13L,
3L, 6L, 9L, 12L, 2L, 5L, 8L, 10L, 11L, 13L, 4L, 6L, 7L, 10L,
6L, 9L, 11L, 5L, 8L, 6L, 9L, 5L, 8L, 11L, 4L, 7L, 9L, 10L, 3L,
5L, 6L, 9L, 12L, 2L, 5L, 8L, 11L, 4L, 7L, 10L, 13L, 3L, 6L, 9L,
11L, 12L, 2L, 4L, 5L, 8L, 11L, 4L, 7L, 10L, 13L, 3L, 6L, 9L,
12L, 2L, 5L, 8L, 10L, 11L, 13L, 4L, 6L, 7L, 10L, 6L, 9L, 11L,
5L, 8L, 6L, 9L, 5L, 8L, 11L, 4L, 7L, 9L, 10L, 3L, 5L, 6L, 9L,
12L, 2L, 5L, 8L, 11L, 4L, 7L, 10L, 13L, 3L, 6L, 9L, 11L, 12L,
2L, 4L, 5L, 8L, 11L, 4L, 7L, 10L, 13L, 3L, 6L, 9L, 12L, 2L, 5L,
8L, 10L, 11L, 13L, 4L, 6L, 7L, 10L, 6L, 9L, 11L, 5L, 8L, 6L,
9L, 5L, 8L, 11L, 4L, 7L, 9L, 10L, 3L, 5L, 6L, 9L, 12L, 2L, 5L,
8L, 11L, 4L, 7L, 10L, 13L, 3L, 6L, 9L, 11L, 12L, 2L, 4L, 5L,
8L, 11L, 4L, 7L, 10L, 13L, 3L, 6L, 9L, 12L, 2L, 5L, 8L, 10L,
11L, 13L, 4L, 6L, 7L, 10L, 6L, 9L, 11L, 5L, 8L), z = c(-0.004858322,
-0.003678845, -0.001656884, -0.001825381, 0.00070207, 0.00120756,
0.000533573, 0.001039063, -0.002499368, -0.001319891, 0.00070207,
0.003566514, 0.007947429, -0.000645904, 2.80828e-05, 0.000533573,
0.004408998, 0.003735011, 0.01098037, 0.002050044, -0.001151394,
0.00221854, -0.001825381, -0.000645904, 0.005251481, 0.011317364,
-0.001488388, 0.00120756, 0.004072004, -0.000645904, -0.005026819,
0.008789913, 0.006767952, -0.003510349, 0.001881547, 0.00070207,
-0.000982898, -0.001656884, 0.001376057, -0.001656884, -0.002330871,
0.001376057, -0.003341852, 0.002387037, NA, -0.00704878, 0.00171305,
-0.001319891, -0.006374793, -0.004184335, 0.004914488, -0.003004858,
0.001376057, -0.018001067, -0.012103682, -0.003928051, -0.005505112,
-0.005347406, -0.004243463, -0.008659235, -0.001404753, 0.002537901,
0.002537901, NA, -0.004085757, -0.002666402, -0.003454933, 0.001118545,
-0.006293643, -0.002824108, 0.00458808, 0.003011019, 0.002064782,
0.002064782, -0.000143104, 0.000330015, -0.004243463, 0.002222488,
0.004272668, 0.003011019, 0.004430374, 0.000330015, 0.000172309,
0.004114962, 0.005534317, 0.006322848, 0.004114962, 0.002380194,
0.003957256, 0.001118545, -0.000616222, 0.003326431, 0.005376611,
-0.002824108, 0.005376611, 1.46024e-05, 0.011054032, 0.001591664,
-0.001089341, -0.000616222, -0.006609055, 0.002380194, 0.002222488,
0.001907076, 0.000330015, 1.46024e-05, -0.004243463, -0.003612639,
-0.014021244, -0.007397586, -0.007748634, -0.005559269, -0.004308204,
-0.006184802, -0.010719915, NA, -0.000242241, 0.00319819, NA,
-0.002587989, -0.003369905, -0.003682671, NA, -0.006341185, -0.001493306,
0.003041806, NA, -0.00071139, -0.001806073, 0.001165208, 0.003667339,
-0.003369905, 0.003823722, 0.00272904, 0.002885423, 0.001790741,
-0.003369905, -0.001806073, -0.002744372, -0.001024157, 0.003667339,
0.005387554, 0.003510956, 0.002572657, -0.00118054, -0.004933736,
-0.001336923, 0.011017349, 0.000383292, 0.005231171, 0.000852442,
0.001165208, 0.003041806, 0.001947124, -0.002431605, -0.006653952,
0.00319819, 0.008046069, 0.008358835, 0.00663862, 0.003823722,
-0.000398624, -0.002900755, -0.002275222, -0.001962456, -0.002808585,
-0.008026171, 3.73711e-05, 0.000353588, -0.008974823, 0.004464414,
0.003831979, 0.001144132, -0.000911281, 0.003990088, 0.003831979,
0.003990088, -0.000278846, -0.01182078, 0.007626588, 0.00857524,
0.006836044, -0.004863998, 0.007152262, 0.004148197, 0.001460349,
-0.017512692, 0.008733348, 0.008259022, 0.00493874, -0.002492368,
-0.01292754, 0.006677936, 0.006994153, 0.004464414, 0.005096849,
-0.003915346, 0.011737413, 0.005571175, 0.001460349, -0.022888387,
0.007942805, 0.009365783, -0.001701824, -0.008974823, 0.009207674,
0.005571175, 0.003357653, -0.00581265, -0.007077519, -0.018619453,
0.006836044, 0.002725219, 0.003357653, -0.004705889, 0.000353588,
-0.002808585, -0.007709954, -0.007235628, -0.008026171)), class = "data.frame", row.names = c(NA,
-220L))
Resulting Plot:

How do I draw a line over the Poisson curve?

How do I draw a line over my Poisson curve in R?
This is the code I used for my plot;
plot(dogbites$daily.dogbites, dpois(dogbites$daily.dogbites, dogbites_lambda),ylab="prob(x)", main="Poisson dog bites")
and this is the plot I got:
I'm hoping to get something like this:
May I know what code can I use for this?
Edit: I tried lines function and type = "o" but I got this instead
> dput(dogbites)
structure(list(daily.dogbites = c(1L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 0L, 1L, 3L, 0L, 6L, 9L, 15L, 3L, 4L, 3L,
7L, 6L, 1L, 2L, 3L, 4L, 2L, 5L, 3L, 1L, 6L, 2L, 0L, 0L, 3L, 3L,
6L, 1L, 3L, 2L, 2L, 5L, 6L, 7L, 4L, 10L, 4L, 18L, 4L, 3L, 2L,
5L, 4L, 3L, 2L, 6L, 4L, 6L, 6L, 1L, 2L, 5L, 10L, 4L, 4L, 3L,
0L, 3L, 4L, 2L, 3L, 3L, 5L, 5L, 5L, 8L, 13L, 10L, 12L, 4L, 5L,
3L, 3L, 5L, 4L, 2L, 6L, 4L, 2L, 1L, 3L, 3L, 7L, 5L, 3L, 2L, 5L,
6L, 5L, 3L, 6L, 5L, 3L, 6L, 5L, 9L, 7L, 8L, 12L, 5L, 2L, 6L,
8L, 4L, 2L, 3L, 6L, 6L, 7L, 6L, 5L, 3L, 3L, 6L, 4L, 3L, 6L, 2L,
2L, 6L, 2L, 4L, 5L, 3L, 4L, 5L, 9L, 12L, 9L, 16L, 7L, 3L, 2L,
3L, 0L, 1L, 1L, 2L, 2L, 2L, 3L, 1L, 2L, 3L, 6L, 4L, 6L, 2L, 6L,
5L, 8L, 3L, 3L, 6L, 7L, 5L, 9L, 18L, 22L, 0L, 7L, 5L, 7L, 1L,
5L, 2L, 4L, 1L, 4L, 5L, 3L, 9L, 5L, 4L, 2L, 4L, 4L, 0L, 4L, 4L,
5L, 4L, 9L, 8L, 9L, 7L, 4L, 13L, 12L, 24L, 7L, 4L, 5L, 10L, 2L,
2L, 3L, 8L, 8L, 4L, 6L, 6L, 3L, 7L, 6L, 2L, 6L, 5L, 2L, 1L, 7L,
0L, 8L, 11L, 2L, 10L, 3L, 7L, 9L, 10L, 7L, 2L, 2L, 5L, 2L, 1L,
8L, 4L, 4L, 5L, 3L, 3L, 2L, 4L, 7L, 3L, 2L, 1L, 3L, 7L, 9L, 8L,
2L, 4L, 8L, 7L, 4L, 9L, 21L, 3L, 2L, 1L, 5L, 3L, 4L, 3L, 3L,
4L, 4L, 2L, 5L, 5L, 2L, 3L, 1L, 4L, 4L, 0L, 1L, 7L, 4L, 2L, 2L,
1L, 5L, 6L, 3L, 7L, 7L, 14L, 4L, 1L, 4L, 6L, 6L, 1L, 2L, 3L,
2L, 0L, 8L, 3L, 1L, 5L, 1L, 4L, 3L, 5L, 7L, 0L, 3L, 3L, 5L, 2L,
4L, 7L, 6L, 7L, 9L, 19L, 5L, 0L, 3L, 0L, 1L, 3L, 4L, 1L, 5L,
2L, 4L, 3L, 6L, 3L, 4L, 7L, 5L, 9L, 3L, 7L, 6L, 5L, 3L, 6L, 5L,
3L, 5L, 8L, 12L, 5L, 17L, 3L, 3L, 2L, 4L, 5L, 4L, 2L, 2L, 1L,
3L, 5L, 4L, 3L, 2L, 1L, 2L, 4L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L
)), class = "data.frame", row.names = c(NA, -378L))
> dput(dogbites_lambda)
4.50529100529101
You need to sort the data by the x axis values
set.seed(42)
x = sample(1:25)
y = dpois(x, 5)
graphics.off()
plot(sort(x), y[order(x)], type = "o")

barchart - axis ticks are not adjusted according to the bars

I have to draw a bar chart in R ggplot2 with multiple variables (i.e each bar for BMI, weight, cholesterol, Blood pressure etc) in each group ( i.e. different populations ex: Indian, Korean, Philipinos etc.) But the bars are overflowing to the next group in the axis. for example: the bars of the Indian group is overflowing to Korean group. The axis marks are not adjusted accordingly. I have attached the figure .. can someone please help. Following is my code. dput(data) is also given.
p = ggplot(data = t,
aes(x = factor(Population, levels = names(sort(table(Population), increasing = TRUE))),
y = Snp_Count,
group = factor(Trait, levels = c("BMI", "DBP", "HDL", "Height", "LDL", "TC", "TG", "WC", "Weight"),
ordered = TRUE)))
p = p + geom_bar(aes(fill = Trait),
position = position_dodge(preserve = "single"),
stat = "identity") +
scale_fill_manual(values = c("#28559A", "#3EB650", "#E56B1F", "#A51890", "#FCC133", "#663300", "#6666ff", "#ff3300", "#ff66ff")) +
coord_flip()
structure(list(Trait = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L), .Label = c("BMI",
"DBP", "HDL", "HT", "LDL", "TC", "TG", "WC", "Weight"), class = "factor"),
Association = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = "Direct", class = "factor"), TraitClass = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Anthropometric",
"BP", "Lipid"), class = "factor"), Population = structure(c(2L,
3L, 4L, 5L, 7L, 8L, 10L, 11L, 12L, 13L, 22L, 24L, 3L, 5L,
11L, 22L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 18L, 20L, 28L, 5L, 7L, 13L, 14L, 1L, 3L, 5L, 7L,
9L, 11L, 12L, 16L, 18L, 20L, 22L, 5L, 6L, 7L, 10L, 12L, 18L,
20L, 3L, 5L, 6L, 7L, 8L, 11L, 12L, 13L, 14L, 15L, 18L, 19L,
20L, 21L, 22L, 23L, 26L, 28L, 3L, 4L, 5L, 8L, 12L, 22L, 24L,
3L, 5L, 7L, 8L, 17L, 25L, 27L), .Label = c("ACB", "AFR",
"ASW", "ASW/ACB", "CEU", "CHB", "EAS", "Filipino", "FIN",
"GBR", "Hispanic", "Hispanic/Latinos", "JPT", "Korean", "Kuwaiti",
"Micronesian", "Moroccan", "MXL", "Mylopotamos", "Orcadian",
"Pomak", "SAS", "Saudi_Arabian", "Seychellois", "Surinamese",
"Taiwanese", "Turkish", "YRI"), class = "factor"), Snp_Count = c(3L,
12L, 6L, 17L, 2L, 10L, 1L, 6L, 3L, 3L, 10L, 6L, 1L, 1L, 1L,
1L, 2L, 1L, 10L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 1L,
2L, 1L, 2L, 20L, 5L, 4L, 1L, 1L, 2L, 7L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 8L, 2L, 4L, 3L, 1L, 2L, 1L, 4L, 20L, 5L,
11L, 2L, 4L, 3L, 4L, 2L, 3L, 4L, 1L, 1L, 1L, 2L, 2L, 1L,
2L, 3L, 2L, 4L, 4L, 1L, 4L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L
), Gene_Count = c(3L, 9L, 7L, 9L, 2L, 8L, 1L, 7L, 3L, 2L,
8L, 7L, 1L, 1L, 1L, 1L, 2L, 1L, 4L, 1L, 1L, 1L, 1L, 2L, 2L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 9L, 6L, 5L, 1L, 1L, 2L, 5L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 6L, 2L, 3L, 3L, 1L, 2L, 1L, 3L,
10L, 4L, 7L, 1L, 3L, 3L, 4L, 1L, 3L, 5L, 1L, 1L, 1L, 3L,
3L, 1L, 1L, 2L, 2L, 3L, 3L, 1L, 3L, 2L, 3L, 3L, 2L, 3L, 2L,
2L, 2L)), class = "data.frame", row.names = c(NA, -86L))
The total width of each group in your barchart is 0.9 by default, which means that 90% of the area is covered. When you increase the width of the individual bars to 3 they will overlap with other groups, the maximum value for with should thus be 1 and then it will touch the other groups.
I'd suggest in your situation to use facet_wrap instead of a dodged barchart.
Note: geom_col is the same as geom_bar(stat = "identity).
my.df$Trait <- factor(my.df$Trait, levels = c("BMI", "DBP", "HDL", "HT", "LDL", "TC", "TG", "WC", "Weight"))
my.df$Population <- factor(my.df$Population, levels = names(sort(table(my.df$Population), increasing = TRUE)))
ggplot(my.df, aes(x = Trait, y = Snp_Count, fill = Trait)) +
geom_col(width = 1) +
scale_fill_manual(values = c("#28559A", "#3EB650", "#E56B1F", "#A51890", "#FCC133", "#663300", "#6666ff", "#ff3300", "#ff66ff")) +
# Split the data by Population, allow flexible scales and spacing for y axis (Trait)
facet_grid(Population ~ ., scales = "free_y", space = "free_y", switch = "y") +
coord_flip() +
theme(axis.text.y = element_blank(), # Remove Trait labels (indicated by color)
axis.ticks.y = element_blank(), # Remove tick marks
strip.background = element_blank(),
strip.text.y = element_text(angle = 180, hjust = 1), # Rotate Population labels
panel.spacing.y = unit(3, "pt")) # Spacing between groups
Data
my.df <-
structure(list(Trait = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L),
.Label = c("BMI", "DBP", "HDL", "HT", "LDL", "TC", "TG", "WC", "Weight"), class = "factor"),
Population = structure(c(2L, 3L, 4L, 5L, 7L, 8L, 10L, 11L,
12L, 13L, 22L, 24L, 3L, 5L, 11L, 22L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 18L, 20L, 28L, 5L,
7L, 13L, 14L, 1L, 3L, 5L, 7L, 9L, 11L, 12L, 16L, 18L, 20L,
22L, 5L, 6L, 7L, 10L, 12L, 18L, 20L, 3L, 5L, 6L, 7L, 8L,
11L, 12L, 13L, 14L, 15L, 18L, 19L, 20L, 21L, 22L, 23L, 26L,
28L, 3L, 4L, 5L, 8L, 12L, 22L, 24L, 3L, 5L, 7L, 8L, 17L,
25L, 27L),
.Label = c("ACB", "AFR", "ASW", "ASW/ACB", "CEU",
"CHB", "EAS", "Filipino", "FIN", "GBR", "Hispanic", "Hispanic/Latinos",
"JPT", "Korean", "Kuwaiti", "Micronesian", "Moroccan", "MXL",
"Mylopotamos", "Orcadian", "Pomak", "SAS", "Saudi_Arabian",
"Seychellois", "Surinamese", "Taiwanese", "Turkish", "YRI"), class = "factor"),
Snp_Count = c(3L, 12L, 6L, 17L, 2L,
10L, 1L, 6L, 3L, 3L, 10L, 6L, 1L, 1L, 1L, 1L, 2L, 1L, 10L,
1L, 1L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 1L, 2L, 1L, 2L, 20L,
5L, 4L, 1L, 1L, 2L, 7L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 8L,
2L, 4L, 3L, 1L, 2L, 1L, 4L, 20L, 5L, 11L, 2L, 4L, 3L, 4L,
2L, 3L, 4L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 3L, 2L, 4L, 4L, 1L,
4L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L)),
class = "data.frame", row.names = c(NA, -86L))

How to read multiple line formula for systemfit in R

I am using systemfit to run system of equations using SUR method. I need to read long (multiple line) formula.My simple reproducible dataset can be accessed using following codes.
dat<-structure(list(Time = structure(c(9L, 7L, 15L, 1L, 17L, 13L,
11L, 3L, 23L, 21L, 19L, 5L, 10L, 8L, 16L, 2L, 18L, 14L, 12L,
4L, 24L, 22L, 20L, 6L), .Label = c("Apr-00", "Apr-01", "Aug-00",
"Aug-01", "Dec-00", "Dec-01", "Feb-00", "Feb-01", "Jan-00", "Jan-01",
"Jul-00", "Jul-01", "Jun-00", "Jun-01", "Mar-00", "Mar-01", "May-00",
"May-01", "Nov-00", "Nov-01", "Oct-00", "Oct-01", "Sep-00", "Sep-01"
), class = "factor"), ID = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L), .Label = c("A", "B"), class = "factor"), y1 = c(25L,
14L, 45L, 15L, 24L, 17L, 18L, 19L, 14L, 15L, 25L, 14L, 45L, 15L,
24L, 17L, 18L, 19L, 14L, 15L, 25L, 14L, 45L, 15L), y2 = c(4L,
3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L, 4L, 2L, 5L, 4L, 3L, 4L, 5L, 1L,
4L, 5L, 3L, 6L, 4L, 2L, 5L), x1 = c(3L, 4L, 1L, 8L, 6L, 7L, 9L,
7L, 3L, 1L, 2L, 5L, 6L, 3L, 4L, 1L, 8L, 6L, 7L, 9L, 7L, 3L, 1L,
2L), x2 = c(4L, 3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L, 4L, 2L, 5L, 4L,
3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L, 4L, 2L, 5L), x3 = c(3L, 4L, 2L,
8L, 6L, 7L, 9L, 7L, 3L, 1L, 2L, 5L, 6L, 3L, 4L, 2L, 8L, 6L, 7L,
9L, 7L, 3L, 1L, 2L), x4 = c(4L, 3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L,
4L, 2L, 5L, 4L, 3L, 4L, 5L, 1L, 4L, 5L, 3L, 6L, 4L, 2L, 5L),
x5 = c(3L, 4L, 3L, 8L, 6L, 7L, 9L, 7L, 3L, 1L, 2L, 5L, 6L,
3L, 4L, 3L, 8L, 6L, 7L, 9L, 7L, 3L, 1L, 2L)), .Names = c("Time",
"ID", "y1", "y2", "x1", "x2", "x3", "x4", "x5"), class = "data.frame", row.names = c(NA,
-24L))
My example formula is like this,
model1<- y1 ~ x1 + x2 + x3
+ x4 +x5
eqSystem <- list(model1)
library(systemfit)
fit_prod_SUR <- systemfit(eqSystem, method= "SUR", data=dat)
print(fit_prod_SUR)
I have to include several very long formulas into eqSystem. But my problem is since my formula (e.g. model1) are very long it has got multiple lines. When I run the eqSystem with systemfit, it reads only the variables in the very first line of each formula. I tried with following code, but it does not work.
model1<- (get(paste("y1 ~ x1 + x2 + x3",
" + x4 + x5", sep="")))
But it does not take as a formula. Please could anyone help me to how to read all variables (in multiple lines) of formula in R.

Resources