如何在ggtern中旋转三元图

时间:2019-10-23 09:32:45

标签: r ggplot2 ggtern

我以三级尺度收集了这些数据,受访者点击了三角形内的一个点以显示某人对情况的反应:

    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")

,并希望创建一个三元图:

enter image description here

到目前为止,我有以下代码:

plot <- ggtern(data=behavior,aes(x=Respectfully,
                                             z=Transparently,
                                             y=Impartially)) +
  geom_point(size=3,fill="yellow",color="red",shape=21)
plot

这给了我这个

enter image description here

如何旋转三角形画布以适合情节? 我已经搜索过,但找不到在线帮助。

我不想旋转整个图,仅旋转triangle。我想按原样保留points

1 个答案:

答案 0 :(得分:2)

您可以使用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

enter image description here