facet_grid 值的奇怪重新排列
facet_grid weird rearrangement of values
我有这个图是我在 R 中使用 ggplot2 生成的。
生成此图的代码是:
plot <- ggplot(mockdata, aes(variable, Measurement)) +
geom_tile(aes(fill = mockdata$plotval), colour = "dark red") + facet_grid(~type, scales='free', space='free') + scale_fill_gradient2(limits=c(-20, 20),high = "firebrick3", low = "dodgerblue4") +
theme_minimal() + theme(axis.text.x=element_text(size=28, angle=90), axis.text.y=element_text(size=28, face = "italic")) +
labs(title="", x="", y="", fill="") + theme(strip.text.x=element_blank(),strip.text.y=element_text(size=20, angle=0))
如您所见,我根据 x-axis 变量的大写添加了水平 space。但是现在,我还想根据另一个因素变量添加垂直间距。我只是将代码更改为:
ggplot(mockdata, aes(variable, Measurement)) +
geom_tile(aes(fill = mockdata$plotval), colour = "dark red") + facet_grid(category~type, scales='free', space='free') + scale_fill_gradient2(limits=c(-20, 20),high = "firebrick3", low = "dodgerblue4") +
theme_minimal() + theme(axis.text.x=element_text(size=28, angle=90), axis.text.y=element_text(size=28, face = "italic")) +
labs(title="", x="", y="", fill="") + theme(strip.text.x=element_blank(),strip.text.y=element_text(size=20, angle=0))
上面给出了我想要的外观,但请注意,这些值都乱七八糟!例如 20:b 和 20:c 在第一个图中是蓝色的,但在第二个图中是红色的。第一个图包含正确的值。
几个小时以来,我一直在疯狂地检查我的因子标签,但我似乎找不到问题所在。我想要一个解决方案,比如如何将垂直 space 添加到我的第一个图中,使用 facet_grid 或不使用,这都没有关系,任何可以解释什么的人都会得到特别奖励积分我的第二个情节出错了。
dput(mockdata)
structure(list(Measurement = structure(c(20L, 19L, 18L, 17L,
16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L,
2L, 1L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L,
9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 20L, 19L, 18L, 17L, 16L,
15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L,
1L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L,
8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 20L, 19L, 18L, 17L, 16L, 15L,
14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L,
20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L,
7L, 6L, 5L, 4L, 3L, 2L, 1L, 20L, 19L, 18L, 17L, 16L, 15L, 14L,
13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 20L,
19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L,
6L, 5L, 4L, 3L, 2L, 1L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L,
12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L), .Label = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35",
"36", "37", "38", "39", "40", "41", "42"), class = "factor"),
category = structure(c(3L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 3L, 4L, 4L, 4L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L,
8L, 3L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 8L, 3L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 3L, 4L, 4L, 4L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L,
8L, 3L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 8L, 3L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 3L, 4L, 4L, 4L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L,
8L, 3L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 8L), .Label = c("x1", "x2", "x3", "x4",
"x5", "x6", "x7", "x8", "x9"), class = "factor"), variable = structure(c(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, 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, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 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, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L), .Label = c("A",
"B", "C", "a", "b", "c", "d", "e", "f"), class = "factor"),
Pval = c(42.7006323958918, 0.0125450399252769, 5675.14711907005,
0.0931416002606762, 0.00232094737764211, 0.000216076621032813,
0.00396622838836271, 6.52388877927194, 11.5722289932645,
0.000334263699328083, 27.0431686878052, 327952.740805895,
0.0297787229949035, 0.585782163292434, 36.9115682159781,
4165.1649504391, 52.9995249740471, 6186.78975112519, 7.85106982537471e-05,
294938.11483059, 9197376.02201148, 1.56761799701167e-05,
0.687511811844484, 2951357.69281822, 0.281822039246925, 0.550068489025187,
12173.6665259036, 0.000654862439823334, 0.00448573254652099,
7319.35702087325, 315.359225529075, 5848068.52630072, 13904253.2299896,
6.66288479812568, 69897.571357397, 10503715.2130853, 46675.3343032854,
80.0136913688775, 2.74356992078766, 348201.375999632, 1.07521153836152e-06,
1.98853436745688e-05, 0.400197989005822, 3511901.4371568,
164.269778446034, 3.24558993609286, 65394.4866129748, 55.4132232221762,
4.83069482078633, 38.6041603684776, 37.9912973942591, 104522.510922666,
6345.6890512069, 0.0193603214641399, 9.18538323079328e-09,
0.000103476856048387, 0.000555384674445469, 3.22868352890832e-05,
113007.480780211, 0.000160838575168945, 0.00217855024162056,
8.64496348775897e-06, 7.06449122162668e-07, 0.619370137929941,
0.270921839221627, 0.011388566962421, 937781.722037049, 652.688753412217,
47171.0329654517, 8.70296668276766, 8276277.85721442, 28353.82586081,
175700.845731391, 1551633.67731154, 689.167798328347, 109.943340419374,
11.3781857520997, 1617599.77065294, 37.1569915088865, 4203.89382661281,
117832.471263455, 1251784.09345768, 535.751672862479, 165398.434479864,
2.55163228104252e-09, 9.8013680674497e-10, 129.319151038722,
556.223625027009, 869.236740102022, 3092.82667967769, 4257.32149187776,
772478.486004829, 15.7002509424478, 0.000219697884882267,
0.000427755809814034, 0.192409289349257, 0.280314538898884,
372.959096370547, 0.00465127237377936, 2.10935354960679e-05,
232459.76019099, 5.77106623224624e-08, 0.0483934897590051,
0.0146558784756261, 1.47248474221649e-08, 0.000222461186585379,
852431.075531575, 528.683263593354, 8298.0240769841, 14.7493364766307,
6.2911608490762, 4536740.5530938, 106.089248136605, 99.5504144351031,
114043.212772726, 253658.532323196, 140833.560642241, 3335.43395071637,
36.6239752632138, 198.244201535186, 14553.9246345935, 2.47559453576517,
1469.76758256116, 4809.5093947632, 2111515.77618631, 3211.80355220151,
0.0046904155982774, 8.1507521777127e-07, 0.000265158173925916,
0.0331951291090042, 9.47798135335384e-10, 0.00629215449841144,
8.27956294929558e-05, 0.000192338169994771, 554785.490344723,
793.314954892235, 0.106735781318401, 14029944.8981012, 527616.898199668,
478322.816562339, 0.00139976568423574, 520.741670562665,
1289142.03044888, 5.80426527938221, 0.00134726649987191,
0.370746844567892, 0.000167132571538772, 3182343.07410991,
82449.5457770316, 2687893.44907279, 0.178274475177317, 50.1455573308552,
414876.812590266, 2.60936167209485e-09, 2.32090832789666e-08,
8.42629935014704e-10, 0.000255374171026513, 1.10761356981753e-06,
5.37793701940977e-05, 0.557162933357393, 829.829809862024,
6184566.2549798, 2782.96376300611, 898.722084215034, 0.0049389188839104,
0.736095078701914, 73.501019996704, 280617.802045198, 0.00108189739567757,
139765.97782083, 18925.6574878606, 39945.1297996732, 11654.4707728977,
5.25244181877881, 0.000951333348397858, 0.701154190998343,
3783700.00624337, 1048363.72082207, 627347.0256674, 0.00056428282172991
), effect = c(-0.00504202541860286, 0.0572728382379748, 0.19355610290193,
0.0908419036193052, 0.0753460915818811, 0.0304533379241126,
0.338999529965851, 0.00450925741610117, 0.0142515711297281,
0.0236642558989115, 0.112084463317692, 0.0355492039503297,
0.046179641636787, 0.0833907727035694, 0.0119081147311255,
0.0409084851564839, 0.00974046553876251, 0.00623992766439915,
0.0828237061289605, 0.0460014467529953, 0.0220280811514705,
0.072554252236383, 0.181702209021198, 0.0496502124621067,
0.103706638295506, 0.0514006496664137, -0.09126288844347,
-0.0579011936709518, -0.0313363166032359, -0.0137049341579666,
-0.0538731912627118, -0.0871985756458715, -0.00540516899377108,
-0.0335420569797512, 0.00837464914354496, -0.00433782674791291,
-0.0186401470510755, -0.00957092739050277, 0.0233458885691129,
0.0363082683534594, 0.0949001163895009, 0.0980889928637072,
0.272094653271255, 0.0116498581551015, -0.0239706620213576,
-0.00948922481425107, -0.0463841533571947, -0.000196251500025392,
0.0332074957195669, 0.0306732835672796, -0.078594298822456,
-0.0013592321904609, 0.00823043498271145, -0.0792124313370092,
-0.114084449997195, -0.0535820005729329, -0.0193882875198498,
-0.145900537042366, -0.042750018055737, -0.0353791699868627,
0.0917785141337663, 0.198537943334598, 0.21948014556882,
0.0524090722153662, 0.014529019941343, 0.0986667789371684,
0.013579010005435, -0.0140683606411563, 0.0151127260881476,
0.00348067883725744, -0.0239177792519331, 0.00323518849038519,
0.0248013017682591, -0.0205422166822478, -0.00862063024472445,
-0.0253349156677723, -0.00206032852686476, -0.034685899461899,
0.0291777396060294, -0.00790295204452705, -0.0172764198936056,
0.093523378677899, 0.0966298831466818, 0.0519375468929764,
0.184676539092511, 0.0738557771574706, 0.0610706031136215,
-0.00852528463886119, -0.035804039040301, 0.0096352117901668,
0.0521074840389658, 0.0364758835127577, 0.0267540711492766,
0.134747323978599, 0.109492562370398, 0.0133001291007968,
0.0732780309339287, 0.0303602020342369, 0.0149482630094048,
0.0273990078144707, 0.00299717221567407, 0.100866435181815,
0.114870729540125, 0.0567497200005222, 0.0912124964999035,
0.127694568835571, 0.0999233369545313, -0.0228848084434401,
-0.0199126446791925, 0.0455760222896934, 0.00550931423553266,
0.0169695986729115, 0.00547424764931202, 0.0360297252475284,
0.00940059675048105, 0.00779317291104235, 0.0292808745009825,
0.0146692995987833, 0.107736041982938, 0.0379549009324052,
-0.0245307848578086, 0.00373489473816007, -0.0277668840806,
0.00541292380436789, 0.0109495216225972, 0.0154749859461561,
0.517201286005927, 0.213654141088575, 0.105933886134205,
0.083967352311383, 0.0390362727543106, 0.0541759578921366,
0.0799491572647821, 0.0713475409375969, 0.0830535251532681,
0.0634176325142384, 0.0340343110430986, 0.0741195089506451,
0.0422227419333998, -0.00201868398387451, -0.102142939489265,
0.00990816502366215, -0.0723986947049853, 0.00438771610893309,
0.0614558366658632, 0.112141419906449, 0.206453004881553,
0.0458149211724056, 0.0370232303908095, 0.0104171190238791,
0.174352387892548, 0.0173287004770711, 0.0570322589545976,
0.0919422210688935, 0.206073359134817, 0.144707153996313,
0.0866876754204277, 0.139499693175196, 0.0501563760935562,
0.113150966215879, -0.0615705734418705, -0.0016999262242578,
-0.161924930685107, 0.0055290101159364, 0.106581585830427,
0.0128140174669214, -0.0703636721519287, -0.018257094814349,
-0.100875941503327, -0.0160441944317892, -0.00386698165039997,
-0.00342265706742182, -0.0322326223948505, 0.0280294325939845,
0.0984244986939011, 0.0512777173537761, 0.0352523410798283,
0.13292883383322, 0.0807717506474815, 0.0508596294487826),
direction = c(-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1,
-1, -1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1,
1, 1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1,
1, 1, 1, -1, 1, 1, -1, 1, 1, -1, -1, -1, -1, -1, 1, -1, -1,
1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, -1, -1, -1, 1, 1, 1, -1, -1, -1, -1, -1, -1,
-1, 1, 1, 1, 1, 1, 1, 1), plotval = c(-1.63043430696911,
1.90152795218119, -3.7539771243977, 1.03085630474974, 2.63433470610105,
3.6653922201862, 2.40162228131836, -0.814506548481021, -1.06341701895514,
3.47591078475207, -1.43205757717356, -5.51581126479104, 1.52609393009486,
0.23226385645368, -1.56716249691816, -3.61963220517785, -1.72427197710882,
-3.79146535741686, 4.10507116012102, -5.46973090002207, -6.96366394237768,
4.80475975925492, 0.162719836007062, -6.4700218474543, 0.550025046893605,
0.259583233135038, -4.08542140092089, 3.18384991817596, 2.34816662398371,
-3.86447293152949, -2.49880554038012, -6.7670124529409, -7.14314766872669,
-0.823662304342601, -4.84446208612616, -7.02134293822782,
-4.66908743718463, -1.90316430670692, -0.438316032811778,
-5.54183048300149, 5.96850608374351, 4.70146689878517, 0.397725098023318,
-6.54554231876607, -2.21555767139982, -0.511293648040455,
-4.81554113464696, -1.74361341251133, -0.684009601793095,
-1.58663411108907, -1.57968412486682, -5.01920983414714,
-3.80247878716975, 1.71308743582189, 8.03690271942929, 3.98515677498429,
3.25540610855334, 4.49097452184084, -5.05310719351909, 3.79360978286461,
2.66183241993435, 5.06323683664087, 6.15091911019143, 0.208049737379102,
0.567155984737416, 1.94353092029908, -5.97210176380931, -2.81470612936045,
-4.67367538666088, -0.939667320932661, -6.91783506268839,
-4.45261166774866, -5.24477385196537, -6.19078919714086,
-2.83832497664739, -2.04116892804232, -1.05607301946984,
-6.20887107667165, -1.57004054321228, -3.62365173896932,
-5.07126498609874, -6.09752942863009, -2.72896353578257,
-5.21853139457582, 8.59318191216903, 9.00871330158534, -2.11166284486924,
-2.74524943113182, -2.93913807439764, -3.4903555830589, -3.62913644718831,
-5.88788639290012, -1.19590659394104, 3.65817412418273, 3.368804083124,
0.715773964440957, 0.552354376375251, -2.57166120394098,
2.33242822790069, 4.67585062188463, -5.36634778544318, 7.23874394143661,
1.31521305884959, 1.83398814476682, 7.83194919664647, 3.65274575062554,
-5.93065927361594, -2.72319556226042, -3.91897469061421,
-1.1687724832959, -0.79873078913878, -6.65674394356368, -2.02567137153985,
-1.99804307236447, -5.05706944355335, -5.40424947528169,
-5.14870615952883, -3.52315234504154, -1.56376548199677,
-2.29720049345194, -4.16298012165971, -0.393679515429061,
-3.16724866427777, -3.68210077741043, -6.32459433060349,
-3.50674897408984, 2.32878867454675, 6.08880231131442, 3.57649498051523,
1.47892563787053, 9.02328415005142, 2.20120062219246, 4.0819925875773,
3.71593452037349, -5.74412509417193, -2.89944564130995, 0.971689966478527,
-7.1470559653621, -5.72231869642199, -5.67972109772494, 2.8539446575791,
-2.71662233198973, -6.1103007681231, -0.763747253307228,
2.87054648892738, 0.430922536570879, 3.77693890461838, -6.50274699717143,
-4.91618826741447, -6.42941204883235, 0.748910833398874,
-1.70023246253767, -5.61791916284656, 8.58346572108797, 7.63434201313085,
9.07436311632148, 3.59282303012629, 5.9556117321782, 4.26938428807087,
0.254017783801932, -2.91898903187407, -6.79130924645919,
-3.44450755141886, -2.95362541370008, 2.30636810656965, 0.133066085813731,
-1.86629336596673, -5.44811521866938, 2.96581392463054, -5.14540146724019,
-4.27705097606589, -4.60146383671481, -4.06649255708194,
-0.720361250431011, 3.02166727906391, 0.154186465719317,
-6.57791669570072, -6.02051198354564, -5.797507843288, 3.24850317060798
), type = c("1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2")), .Names = c("Measurement", "category", "variable",
"Pval", "effect", "direction", "plotval", "type"), row.names = c(23L,
24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L,
37L, 38L, 39L, 40L, 41L, 42L, 65L, 66L, 67L, 68L, 69L, 70L, 71L,
72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L,
107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L,
118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 149L, 150L,
151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L, 159L, 160L, 161L,
162L, 163L, 164L, 165L, 166L, 167L, 168L, 191L, 192L, 193L, 194L,
195L, 196L, 197L, 198L, 199L, 200L, 201L, 202L, 203L, 204L, 205L,
206L, 207L, 208L, 209L, 210L, 233L, 234L, 235L, 236L, 237L, 238L,
239L, 240L, 241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L, 249L,
250L, 251L, 252L, 275L, 276L, 277L, 278L, 279L, 280L, 281L, 282L,
283L, 284L, 285L, 286L, 287L, 288L, 289L, 290L, 291L, 292L, 293L,
294L, 317L, 318L, 319L, 320L, 321L, 322L, 323L, 324L, 325L, 326L,
327L, 328L, 329L, 330L, 331L, 332L, 333L, 334L, 335L, 336L, 359L,
360L, 361L, 362L, 363L, 364L, 365L, 366L, 367L, 368L, 369L, 370L,
371L, 372L, 373L, 374L, 375L, 376L, 377L, 378L), class = "data.frame")
非常感谢您的帮助。
像这里那样做(在 aes
fill
中应该是列名称而不是向量):
plot <- ggplot(mockdata, aes(variable, Measurement, fill = plotval)) +
geom_tile(colour = "dark red") +
facet_grid(category~type, scales='free', space='free') +
scale_fill_gradient2(limits=c(-20, 20),high = "firebrick3", low = "dodgerblue4") +
theme_minimal() +
theme(axis.text.x=element_text(size=28, angle=90),
axis.text.y=element_text(size=28, face = "italic"),
strip.text.x=element_blank(),
strip.text.y=element_text(size=20, angle=0)) +
labs(title="", x="", y="", fill="")
我有这个图是我在 R 中使用 ggplot2 生成的。
生成此图的代码是:
plot <- ggplot(mockdata, aes(variable, Measurement)) +
geom_tile(aes(fill = mockdata$plotval), colour = "dark red") + facet_grid(~type, scales='free', space='free') + scale_fill_gradient2(limits=c(-20, 20),high = "firebrick3", low = "dodgerblue4") +
theme_minimal() + theme(axis.text.x=element_text(size=28, angle=90), axis.text.y=element_text(size=28, face = "italic")) +
labs(title="", x="", y="", fill="") + theme(strip.text.x=element_blank(),strip.text.y=element_text(size=20, angle=0))
如您所见,我根据 x-axis 变量的大写添加了水平 space。但是现在,我还想根据另一个因素变量添加垂直间距。我只是将代码更改为:
ggplot(mockdata, aes(variable, Measurement)) +
geom_tile(aes(fill = mockdata$plotval), colour = "dark red") + facet_grid(category~type, scales='free', space='free') + scale_fill_gradient2(limits=c(-20, 20),high = "firebrick3", low = "dodgerblue4") +
theme_minimal() + theme(axis.text.x=element_text(size=28, angle=90), axis.text.y=element_text(size=28, face = "italic")) +
labs(title="", x="", y="", fill="") + theme(strip.text.x=element_blank(),strip.text.y=element_text(size=20, angle=0))
几个小时以来,我一直在疯狂地检查我的因子标签,但我似乎找不到问题所在。我想要一个解决方案,比如如何将垂直 space 添加到我的第一个图中,使用 facet_grid 或不使用,这都没有关系,任何可以解释什么的人都会得到特别奖励积分我的第二个情节出错了。
dput(mockdata)
structure(list(Measurement = structure(c(20L, 19L, 18L, 17L,
16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L,
2L, 1L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L,
9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 20L, 19L, 18L, 17L, 16L,
15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L,
1L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L,
8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 20L, 19L, 18L, 17L, 16L, 15L,
14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L,
20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L,
7L, 6L, 5L, 4L, 3L, 2L, 1L, 20L, 19L, 18L, 17L, 16L, 15L, 14L,
13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 20L,
19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L,
6L, 5L, 4L, 3L, 2L, 1L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L,
12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L), .Label = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35",
"36", "37", "38", "39", "40", "41", "42"), class = "factor"),
category = structure(c(3L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 3L, 4L, 4L, 4L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L,
8L, 3L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 8L, 3L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 3L, 4L, 4L, 4L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L,
8L, 3L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 8L, 3L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 3L, 4L, 4L, 4L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L,
8L, 3L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L,
7L, 7L, 7L, 7L, 7L, 8L), .Label = c("x1", "x2", "x3", "x4",
"x5", "x6", "x7", "x8", "x9"), class = "factor"), variable = structure(c(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, 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, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 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, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L), .Label = c("A",
"B", "C", "a", "b", "c", "d", "e", "f"), class = "factor"),
Pval = c(42.7006323958918, 0.0125450399252769, 5675.14711907005,
0.0931416002606762, 0.00232094737764211, 0.000216076621032813,
0.00396622838836271, 6.52388877927194, 11.5722289932645,
0.000334263699328083, 27.0431686878052, 327952.740805895,
0.0297787229949035, 0.585782163292434, 36.9115682159781,
4165.1649504391, 52.9995249740471, 6186.78975112519, 7.85106982537471e-05,
294938.11483059, 9197376.02201148, 1.56761799701167e-05,
0.687511811844484, 2951357.69281822, 0.281822039246925, 0.550068489025187,
12173.6665259036, 0.000654862439823334, 0.00448573254652099,
7319.35702087325, 315.359225529075, 5848068.52630072, 13904253.2299896,
6.66288479812568, 69897.571357397, 10503715.2130853, 46675.3343032854,
80.0136913688775, 2.74356992078766, 348201.375999632, 1.07521153836152e-06,
1.98853436745688e-05, 0.400197989005822, 3511901.4371568,
164.269778446034, 3.24558993609286, 65394.4866129748, 55.4132232221762,
4.83069482078633, 38.6041603684776, 37.9912973942591, 104522.510922666,
6345.6890512069, 0.0193603214641399, 9.18538323079328e-09,
0.000103476856048387, 0.000555384674445469, 3.22868352890832e-05,
113007.480780211, 0.000160838575168945, 0.00217855024162056,
8.64496348775897e-06, 7.06449122162668e-07, 0.619370137929941,
0.270921839221627, 0.011388566962421, 937781.722037049, 652.688753412217,
47171.0329654517, 8.70296668276766, 8276277.85721442, 28353.82586081,
175700.845731391, 1551633.67731154, 689.167798328347, 109.943340419374,
11.3781857520997, 1617599.77065294, 37.1569915088865, 4203.89382661281,
117832.471263455, 1251784.09345768, 535.751672862479, 165398.434479864,
2.55163228104252e-09, 9.8013680674497e-10, 129.319151038722,
556.223625027009, 869.236740102022, 3092.82667967769, 4257.32149187776,
772478.486004829, 15.7002509424478, 0.000219697884882267,
0.000427755809814034, 0.192409289349257, 0.280314538898884,
372.959096370547, 0.00465127237377936, 2.10935354960679e-05,
232459.76019099, 5.77106623224624e-08, 0.0483934897590051,
0.0146558784756261, 1.47248474221649e-08, 0.000222461186585379,
852431.075531575, 528.683263593354, 8298.0240769841, 14.7493364766307,
6.2911608490762, 4536740.5530938, 106.089248136605, 99.5504144351031,
114043.212772726, 253658.532323196, 140833.560642241, 3335.43395071637,
36.6239752632138, 198.244201535186, 14553.9246345935, 2.47559453576517,
1469.76758256116, 4809.5093947632, 2111515.77618631, 3211.80355220151,
0.0046904155982774, 8.1507521777127e-07, 0.000265158173925916,
0.0331951291090042, 9.47798135335384e-10, 0.00629215449841144,
8.27956294929558e-05, 0.000192338169994771, 554785.490344723,
793.314954892235, 0.106735781318401, 14029944.8981012, 527616.898199668,
478322.816562339, 0.00139976568423574, 520.741670562665,
1289142.03044888, 5.80426527938221, 0.00134726649987191,
0.370746844567892, 0.000167132571538772, 3182343.07410991,
82449.5457770316, 2687893.44907279, 0.178274475177317, 50.1455573308552,
414876.812590266, 2.60936167209485e-09, 2.32090832789666e-08,
8.42629935014704e-10, 0.000255374171026513, 1.10761356981753e-06,
5.37793701940977e-05, 0.557162933357393, 829.829809862024,
6184566.2549798, 2782.96376300611, 898.722084215034, 0.0049389188839104,
0.736095078701914, 73.501019996704, 280617.802045198, 0.00108189739567757,
139765.97782083, 18925.6574878606, 39945.1297996732, 11654.4707728977,
5.25244181877881, 0.000951333348397858, 0.701154190998343,
3783700.00624337, 1048363.72082207, 627347.0256674, 0.00056428282172991
), effect = c(-0.00504202541860286, 0.0572728382379748, 0.19355610290193,
0.0908419036193052, 0.0753460915818811, 0.0304533379241126,
0.338999529965851, 0.00450925741610117, 0.0142515711297281,
0.0236642558989115, 0.112084463317692, 0.0355492039503297,
0.046179641636787, 0.0833907727035694, 0.0119081147311255,
0.0409084851564839, 0.00974046553876251, 0.00623992766439915,
0.0828237061289605, 0.0460014467529953, 0.0220280811514705,
0.072554252236383, 0.181702209021198, 0.0496502124621067,
0.103706638295506, 0.0514006496664137, -0.09126288844347,
-0.0579011936709518, -0.0313363166032359, -0.0137049341579666,
-0.0538731912627118, -0.0871985756458715, -0.00540516899377108,
-0.0335420569797512, 0.00837464914354496, -0.00433782674791291,
-0.0186401470510755, -0.00957092739050277, 0.0233458885691129,
0.0363082683534594, 0.0949001163895009, 0.0980889928637072,
0.272094653271255, 0.0116498581551015, -0.0239706620213576,
-0.00948922481425107, -0.0463841533571947, -0.000196251500025392,
0.0332074957195669, 0.0306732835672796, -0.078594298822456,
-0.0013592321904609, 0.00823043498271145, -0.0792124313370092,
-0.114084449997195, -0.0535820005729329, -0.0193882875198498,
-0.145900537042366, -0.042750018055737, -0.0353791699868627,
0.0917785141337663, 0.198537943334598, 0.21948014556882,
0.0524090722153662, 0.014529019941343, 0.0986667789371684,
0.013579010005435, -0.0140683606411563, 0.0151127260881476,
0.00348067883725744, -0.0239177792519331, 0.00323518849038519,
0.0248013017682591, -0.0205422166822478, -0.00862063024472445,
-0.0253349156677723, -0.00206032852686476, -0.034685899461899,
0.0291777396060294, -0.00790295204452705, -0.0172764198936056,
0.093523378677899, 0.0966298831466818, 0.0519375468929764,
0.184676539092511, 0.0738557771574706, 0.0610706031136215,
-0.00852528463886119, -0.035804039040301, 0.0096352117901668,
0.0521074840389658, 0.0364758835127577, 0.0267540711492766,
0.134747323978599, 0.109492562370398, 0.0133001291007968,
0.0732780309339287, 0.0303602020342369, 0.0149482630094048,
0.0273990078144707, 0.00299717221567407, 0.100866435181815,
0.114870729540125, 0.0567497200005222, 0.0912124964999035,
0.127694568835571, 0.0999233369545313, -0.0228848084434401,
-0.0199126446791925, 0.0455760222896934, 0.00550931423553266,
0.0169695986729115, 0.00547424764931202, 0.0360297252475284,
0.00940059675048105, 0.00779317291104235, 0.0292808745009825,
0.0146692995987833, 0.107736041982938, 0.0379549009324052,
-0.0245307848578086, 0.00373489473816007, -0.0277668840806,
0.00541292380436789, 0.0109495216225972, 0.0154749859461561,
0.517201286005927, 0.213654141088575, 0.105933886134205,
0.083967352311383, 0.0390362727543106, 0.0541759578921366,
0.0799491572647821, 0.0713475409375969, 0.0830535251532681,
0.0634176325142384, 0.0340343110430986, 0.0741195089506451,
0.0422227419333998, -0.00201868398387451, -0.102142939489265,
0.00990816502366215, -0.0723986947049853, 0.00438771610893309,
0.0614558366658632, 0.112141419906449, 0.206453004881553,
0.0458149211724056, 0.0370232303908095, 0.0104171190238791,
0.174352387892548, 0.0173287004770711, 0.0570322589545976,
0.0919422210688935, 0.206073359134817, 0.144707153996313,
0.0866876754204277, 0.139499693175196, 0.0501563760935562,
0.113150966215879, -0.0615705734418705, -0.0016999262242578,
-0.161924930685107, 0.0055290101159364, 0.106581585830427,
0.0128140174669214, -0.0703636721519287, -0.018257094814349,
-0.100875941503327, -0.0160441944317892, -0.00386698165039997,
-0.00342265706742182, -0.0322326223948505, 0.0280294325939845,
0.0984244986939011, 0.0512777173537761, 0.0352523410798283,
0.13292883383322, 0.0807717506474815, 0.0508596294487826),
direction = c(-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1,
-1, -1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1,
1, 1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1,
1, 1, 1, -1, 1, 1, -1, 1, 1, -1, -1, -1, -1, -1, 1, -1, -1,
1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, -1, -1, -1, 1, 1, 1, -1, -1, -1, -1, -1, -1,
-1, 1, 1, 1, 1, 1, 1, 1), plotval = c(-1.63043430696911,
1.90152795218119, -3.7539771243977, 1.03085630474974, 2.63433470610105,
3.6653922201862, 2.40162228131836, -0.814506548481021, -1.06341701895514,
3.47591078475207, -1.43205757717356, -5.51581126479104, 1.52609393009486,
0.23226385645368, -1.56716249691816, -3.61963220517785, -1.72427197710882,
-3.79146535741686, 4.10507116012102, -5.46973090002207, -6.96366394237768,
4.80475975925492, 0.162719836007062, -6.4700218474543, 0.550025046893605,
0.259583233135038, -4.08542140092089, 3.18384991817596, 2.34816662398371,
-3.86447293152949, -2.49880554038012, -6.7670124529409, -7.14314766872669,
-0.823662304342601, -4.84446208612616, -7.02134293822782,
-4.66908743718463, -1.90316430670692, -0.438316032811778,
-5.54183048300149, 5.96850608374351, 4.70146689878517, 0.397725098023318,
-6.54554231876607, -2.21555767139982, -0.511293648040455,
-4.81554113464696, -1.74361341251133, -0.684009601793095,
-1.58663411108907, -1.57968412486682, -5.01920983414714,
-3.80247878716975, 1.71308743582189, 8.03690271942929, 3.98515677498429,
3.25540610855334, 4.49097452184084, -5.05310719351909, 3.79360978286461,
2.66183241993435, 5.06323683664087, 6.15091911019143, 0.208049737379102,
0.567155984737416, 1.94353092029908, -5.97210176380931, -2.81470612936045,
-4.67367538666088, -0.939667320932661, -6.91783506268839,
-4.45261166774866, -5.24477385196537, -6.19078919714086,
-2.83832497664739, -2.04116892804232, -1.05607301946984,
-6.20887107667165, -1.57004054321228, -3.62365173896932,
-5.07126498609874, -6.09752942863009, -2.72896353578257,
-5.21853139457582, 8.59318191216903, 9.00871330158534, -2.11166284486924,
-2.74524943113182, -2.93913807439764, -3.4903555830589, -3.62913644718831,
-5.88788639290012, -1.19590659394104, 3.65817412418273, 3.368804083124,
0.715773964440957, 0.552354376375251, -2.57166120394098,
2.33242822790069, 4.67585062188463, -5.36634778544318, 7.23874394143661,
1.31521305884959, 1.83398814476682, 7.83194919664647, 3.65274575062554,
-5.93065927361594, -2.72319556226042, -3.91897469061421,
-1.1687724832959, -0.79873078913878, -6.65674394356368, -2.02567137153985,
-1.99804307236447, -5.05706944355335, -5.40424947528169,
-5.14870615952883, -3.52315234504154, -1.56376548199677,
-2.29720049345194, -4.16298012165971, -0.393679515429061,
-3.16724866427777, -3.68210077741043, -6.32459433060349,
-3.50674897408984, 2.32878867454675, 6.08880231131442, 3.57649498051523,
1.47892563787053, 9.02328415005142, 2.20120062219246, 4.0819925875773,
3.71593452037349, -5.74412509417193, -2.89944564130995, 0.971689966478527,
-7.1470559653621, -5.72231869642199, -5.67972109772494, 2.8539446575791,
-2.71662233198973, -6.1103007681231, -0.763747253307228,
2.87054648892738, 0.430922536570879, 3.77693890461838, -6.50274699717143,
-4.91618826741447, -6.42941204883235, 0.748910833398874,
-1.70023246253767, -5.61791916284656, 8.58346572108797, 7.63434201313085,
9.07436311632148, 3.59282303012629, 5.9556117321782, 4.26938428807087,
0.254017783801932, -2.91898903187407, -6.79130924645919,
-3.44450755141886, -2.95362541370008, 2.30636810656965, 0.133066085813731,
-1.86629336596673, -5.44811521866938, 2.96581392463054, -5.14540146724019,
-4.27705097606589, -4.60146383671481, -4.06649255708194,
-0.720361250431011, 3.02166727906391, 0.154186465719317,
-6.57791669570072, -6.02051198354564, -5.797507843288, 3.24850317060798
), type = c("1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2")), .Names = c("Measurement", "category", "variable",
"Pval", "effect", "direction", "plotval", "type"), row.names = c(23L,
24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L,
37L, 38L, 39L, 40L, 41L, 42L, 65L, 66L, 67L, 68L, 69L, 70L, 71L,
72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L,
107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L,
118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 149L, 150L,
151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L, 159L, 160L, 161L,
162L, 163L, 164L, 165L, 166L, 167L, 168L, 191L, 192L, 193L, 194L,
195L, 196L, 197L, 198L, 199L, 200L, 201L, 202L, 203L, 204L, 205L,
206L, 207L, 208L, 209L, 210L, 233L, 234L, 235L, 236L, 237L, 238L,
239L, 240L, 241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L, 249L,
250L, 251L, 252L, 275L, 276L, 277L, 278L, 279L, 280L, 281L, 282L,
283L, 284L, 285L, 286L, 287L, 288L, 289L, 290L, 291L, 292L, 293L,
294L, 317L, 318L, 319L, 320L, 321L, 322L, 323L, 324L, 325L, 326L,
327L, 328L, 329L, 330L, 331L, 332L, 333L, 334L, 335L, 336L, 359L,
360L, 361L, 362L, 363L, 364L, 365L, 366L, 367L, 368L, 369L, 370L,
371L, 372L, 373L, 374L, 375L, 376L, 377L, 378L), class = "data.frame")
非常感谢您的帮助。
像这里那样做(在 aes
fill
中应该是列名称而不是向量):
plot <- ggplot(mockdata, aes(variable, Measurement, fill = plotval)) +
geom_tile(colour = "dark red") +
facet_grid(category~type, scales='free', space='free') +
scale_fill_gradient2(limits=c(-20, 20),high = "firebrick3", low = "dodgerblue4") +
theme_minimal() +
theme(axis.text.x=element_text(size=28, angle=90),
axis.text.y=element_text(size=28, face = "italic"),
strip.text.x=element_blank(),
strip.text.y=element_text(size=20, angle=0)) +
labs(title="", x="", y="", fill="")