主頁 > 資料庫 > 更改ggplots中特定方面的比例以避免混亂

更改ggplots中特定方面的比例以避免混亂

2022-02-25 06:21:24 資料庫

我想手動更改 ggplot 中某些特定方面的比例。我嘗試設定 scales 和 space = "free" 但我沒有得到想要的行為。我還想讓圖表看起來更大,我意識到當我使用“主題(aspect.ratio = 5/5)”時它會縮小情節

我想手動更改 ggplot 中某些特定方面的比例。我嘗試設定 scales 和 space = "free" 但我沒有得到想要的行為。我還想讓圖表看起來更大,我意識到當我使用“主題(aspect.ratio = 5/5)”時它會縮小情節

dataLong <- structure(list(Group = c("Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", 
"Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_1", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", "Grp_2", 
"Grp_2"), Index = c("1", "2", "3", "1", "2", "3", "1", "2", "3", 
"1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", 
"2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", 
"3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", 
"1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", 
"2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", 
"3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", 
"1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", 
"2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", 
"3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", 
"1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", 
"2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", 
"3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", 
"1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", 
"2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", 
"3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", 
"1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", 
"2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", 
"3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", 
"1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", 
"2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", 
"3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", 
"1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", 
"2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", 
"3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", 
"1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", 
"2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", 
"3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", 
"1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", 
"2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", 
"3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", 
"1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", 
"2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", 
"3", "1", "2", "3", "1", "2", "3"), Eye = c(0.1625, 0.152, 0.329, 
0.6145, 1.401, 2.3125, 0.1335, 1.111, 1.294, 0.083, 2.372, 2.554, 
0.1165, 0.2005, 0.3085, 0.2585, 0.4805, 0.7555, 0.2085, 1.663, 
1.913, 0.549, 1.97, 2.336, 0.142, 0.719, 0.869, 0.1585, 1.3735, 
1.6545, 0.1835, 1.283, 1.45, 0.2585, 0.795, 1.2595, 0.1835, 0.1625, 
0.3625, 0.334, 1.406, 1.811, 0.1505, 1.0035, 1.304, 0.166, 2.323, 
2.656, 0.1085, 0.167, 0.292, 0.25, 0.2725, 0.5305, 0.1505, 1.453, 
1.537, 0.452, 1.265, 1.947, 0.117, 0.343, 0.653, 0.183, 1.055, 
1.424, 0.1745, 1.199, 1.3655, 0.3335, 0.3825, 0.619, 0.158, 0.923, 
1.08, 0.3, 2.033, 2.337, 0.071, 0.9435, 1.0105, 0.133, 1.76, 
1.947, 0.15, 0.2335, 0.5005, 0.3085, 0.473, 0.7905, 0.133, 2.543, 
2.626, 0.3415, 2.2415, 2.331, 0.125, 0.7535, 0.862, 0.25, 1.691, 
2.008, 0.158, 1.437, 1.554, 0.3965, 1.2865, 1.7715, 0.158, 0.314, 
0.453, 0.167, 0.566, 0.666, 0.1, 0.2665, 0.422, 0.117, 0.166, 
0.284, 0.1745, 0.5945, 0.753, 0.1335, 0.514, 0.6645, 0.134, 0.333, 
0.467, 0.25, 0.498, 0.767, 0.1335, 3.879, 4.0125, 0.125, 0.309, 
0.4515, 0.1, 0.344, 0.439, 0.175, 2.2515, 2.6085, 0.1835, 0.4295, 
0.596, 0.133, 0.366, 0.5, 0.1, 0.333, 0.433, 0.125, 0.167, 0.3085, 
0.167, 0.167, 0.35, 0.184, 0.333, 0.55, 0.1415, 0.333, 0.4665, 
0.4805, 0.346, 0.785, 0.1335, 3.161, 3.2945, 0.1085, 0.3, 0.41, 
0.133, 0.434, 0.584, 0.133, 0.383, 0.516, 0.167, 0.4, 0.533, 
0.1335, 1.035, 1.1575, 0.116, 0.334, 0.4665, 0.134, 0.15, 0.3, 
0.1505, 0.6835, 0.842, 0.1415, 1.417, 1.575, 0.092, 1.99, 2.3285, 
0.367, 0.646, 1.03, 0.166, 4.727, 5.045, 0.1, 0.89, 0.9645, 0.167, 
0.804, 0.999, 0.15, 1.695, 1.845, 0.142, 0.254, 0.408, 0.2, 0.445, 
0.6785, 0.1505, 0.3665, 0.5, 0.168, 1.353, 1.588, 0.116, 0.1665, 
0.2665, 0.2, 0.2745, 0.425, 0.3585, 0.5535, 1.24, 0.1835, 0.2985, 
0.5605, 0.1165, 0.166, 0.2855, 0.1585, 1.127, 1.2575, 0.175, 
1.238, 1.356, 0.258, 1.068, 1.4355, 0.154, 0.1805, 0.31, 0.167, 
0.8915, 1.075, 0.167, 0.635, 0.901, 0.136, 1.631, 1.763, 0.1, 
0.2165, 0.3, 0.2085, 0.252, 0.46, 0.3445, 0.1825, 1.11, 0.192, 
0.304, 0.475, 0.116, 0.1775, 0.3, 0.116, 1.005, 1.1245, 0.166, 
1.207, 1.374, 0.2, 0.6085, 0.9005, 0.129, 0.1765, 0.3015, 0.2, 
0.661, 0.911, 0.1165, 0.4775, 0.7605, 0.1165, 1.431, 1.584, 0.117, 
0.1835, 0.3085, 0.242, 0.3365, 0.573, 0.327, 1.236, 1.515, 0.192, 
0.324, 0.541, 0.1, 0.1585, 0.2505, 0.167, 1.425, 1.68, 0.154, 
1.6555, 1.8555, 0.242, 0.646, 1.165, 0.125, 0.2, 0.341, 0.133, 
0.596, 0.7125, 0.1495, 0.267, 0.4505, 0.1165, 0.175, 0.297, 0.117, 
0.272, 0.422, 0.117, 0.308, 0.3835, 0.0915, 0.167, 0.267, 0.1585, 
0.167, 0.334, 0.117, 3.0555, 3.164, 0.108, 0.3, 0.384, 0.117, 
0.1745, 0.342, 0.1165, 0.3005, 0.4165, 0.1715, 0.167, 0.35, 0.167, 
0.361, 0.494, 0.133, 0.267, 0.466, 0.116, 0.183, 0.275, 0.133, 
0.246, 0.379, 0.133, 0.166, 0.317, 0.083, 0.1925, 0.275, 0.1865, 
0.168, 0.45, 0.133, 2.668, 2.818, 0.1165, 0.3315, 0.4465, 0.117, 
0.15, 0.3, 0.116, 0.167, 0.3, 0.1, 0.2835, 0.3795, 0.134, 0.367, 
0.533, 0.1165, 0.5105, 0.6145, 0.117, 0.192, 0.276, 0.134, 0.15, 
0.3825, 0.125, 0.4185, 0.5685, 0.083, 0.25, 0.35, 0.225, 0.215, 
0.3985, 0.108, 3.036, 3.1365, 0.125, 0.3085, 0.4335, 0.117, 0.15, 
0.267, 0.1165, 0.254, 0.359), Hand = c(0.369, 1.4485, 1.8075, 
0.75, 2.3315, 2.896, 0.35, 1.8555, 2.222, 0.35, 2.788, 3.056, 
0.2165, 0.9965, 1.23, 0.3835, 1.133, 1.483, 0.517, 2.817, 3.3425, 
0.433, 3.1015, 3.4345, 0.283, 1.3025, 1.5895, 0.367, 2.401, 2.801, 
0.475, 1.45, 1.965, 0.4, 1.5335, 1.911, 0.4125, 1.25, 1.658, 
0.4005, 1.483, 2.3415, 0.35, 1.5815, 1.8805, 0.4, 2.879, 3.301, 
0.2165, 1.0765, 1.2935, 0.392, 1.198, 1.588, 0.5085, 2.475, 3.147, 
0.433, 3.027, 3.461, 0.258, 1.308, 1.508, 0.3665, 1.69, 2.107, 
0.4165, 1.6245, 2.041, 0.383, 1.609, 2.026, 0.329, 1.771, 2.096, 
0.667, 2.406, 2.915, 0.3665, 2.3945, 2.8, 0.3165, 2.574, 2.907, 
0.275, 1.0995, 1.335, 0.466, 1.274, 1.7655, 0.6415, 3.189, 3.894, 
0.4585, 3.2325, 3.7165, 0.2835, 1.6815, 1.9735, 0.433, 2.112, 
2.654, 0.433, 1.992, 2.309, 0.4245, 2.074, 2.541, 0.358, 1.555, 
1.947, 0.4, 2.196, 2.596, 0.3, 1.476, 1.8, 0.367, 1.319, 1.636, 
0.3, 2.3245, 2.5915, 0.267, 1.513, 1.763, 0.434, 2.13, 2.48, 
0.45, 1.533, 1.955, 0.519, 4.0535, 4.6585, 0.3335, 1.393, 1.7415, 
0.3, 1.404, 1.6775, 0.742, 2.479, 3.199, 0.3335, 1.2575, 1.628, 
0.3, 1.627, 1.994, 0.333, 1.627, 1.998, 0.325, 1.2035, 1.5895, 
0.335, 1.972, 2.301, 0.3, 1.627, 1.903, 0.4165, 2.0135, 2.4555, 
0.522, 1.723, 2.1685, 0.3755, 3.549, 3.928, 0.3745, 1.3065, 1.6565, 
0.275, 1.509, 1.743, 0.4, 1.896, 2.296, 0.3, 1.337, 1.57, 0.35, 
1.9335, 2.3835, 0.284, 1.7195, 1.9995, 0.4, 1.614, 1.984, 0.35, 
1.8595, 2.693, 0.325, 2.093, 2.418, 0.4335, 2.756, 3.2325, 0.564, 
1.784, 2.348, 0.466, 4.445, 5.045, 0.3415, 1.954, 2.304, 0.333, 
1.7855, 2.136, 0.567, 2.418, 3.051, 0.3665, 1.73, 2.0245, 0.2845, 
1.301, 1.5885, 0.3, 1.437, 1.687, 0.3995, 2.0635, 2.3985, 0.2585, 
0.85, 1.1, 0.358, 0.958, 1.381, 0.4415, 1.903, 2.413, 0.4, 1.7835, 
2.1765, 0.2745, 1.0625, 1.335, 0.366, 1.831, 2.184, 0.475, 1.581, 
2.014, 0.558, 1.569, 2.2635, 0.3195, 1.479, 1.743, 0.3495, 1.427, 
1.7055, 0.333, 1.166, 1.466, 0.583, 2.1075, 2.54, 0.267, 0.812, 
1.0605, 0.3335, 0.9445, 1.255, 0.6475, 2.0145, 2.588, 0.367, 
1.621, 2.021, 0.283, 0.954, 1.237, 0.391, 1.461, 1.871, 0.467, 
1.742, 2.074, 0.4835, 1.6455, 2.179, 0.354, 1.74, 2.002, 0.383, 
1.35, 1.752, 0.3, 1.365, 1.665, 0.4, 2.157, 2.612, 0.25, 0.786, 
1.04, 0.3165, 1.0795, 1.4045, 0.526, 2.419, 2.892, 0.392, 1.695, 
2.1105, 0.2745, 0.979, 1.254, 0.3745, 2.011, 2.3935, 0.508, 2.128, 
2.748, 0.475, 1.893, 2.4005, 0.329, 1.2055, 1.522, 0.3075, 1.6185, 
1.976, 0.3, 0.999, 1.363, 0.3, 1.453, 1.7445, 0.292, 1.1085, 
1.392, 0.283, 1.151, 1.476, 0.3165, 1.3145, 1.6235, 0.2415, 1.1525, 
1.414, 0.3915, 3.35, 3.6665, 0.3335, 0.95, 1.242, 0.3255, 1.0535, 
1.362, 0.333, 1.376, 1.718, 0.3835, 1.0295, 1.413, 0.3, 1.237, 
1.704, 0.3, 1.209, 1.542, 0.292, 1.0765, 1.3845, 0.2665, 0.99, 
1.2895, 0.3, 1.368, 1.585, 0.342, 1.0525, 1.394, 0.275, 1.293, 
1.588, 0.4, 2.899, 3.203, 0.2655, 0.8785, 1.102, 0.3085, 0.892, 
1.225, 0.334, 0.946, 1.28, 0.341, 1.236, 1.5285, 0.267, 2.03, 
2.297, 0.3195, 1.279, 1.532, 0.317, 1.583, 1.883, 0.283, 1.4125, 
1.679, 0.3165, 1.5555, 1.822, 0.4, 1.245, 1.645, 0.25, 1.2275, 
1.512, 0.3415, 2.8515, 3.245, 0.3165, 1.0295, 1.338, 0.316, 1.132, 
1.465, 0.3335, 1.2335, 1.5585)), row.names = c(NA, -432L), class = c("tbl_df", 
"tbl", "data.frame"))

Index.labs <- c("RT (s)", "MT (s)", "RSP (s)")
names(Index.labs) <- c("1", "2", "3")

Group.labs <- c("Visible", "Remembered")
names(Group.labs) <- c("Grp_1", "Grp_2")

Cors <- dataLong %>% group_by(Group,Index) %>% summarize(Cor=round(cor(Eye,Hand),3))

ggplot(dataLong,aes(x=Hand,y=Eye)) geom_point() 
  facet_grid(Index~Group, labeller = labeller(Index = Index.labs, Group = Group.labs)) 
  geom_text(aes(x=1.5,y=3,label=paste("r=",Cor)),size = 4.5,data=Cors)   theme_bw()   theme(
    axis.text.x = element_text(size = 12,face="bold"),
    axis.text.y = element_text(size = 12, face = "bold"),
    axis.title.y = element_text(vjust= 1.8, size = 20),
    axis.title.x = element_text(vjust= -0.5, size = 18),
    axis.title = element_text(face = "bold"))                                                                  # Change font size
  theme(strip.text.x = element_text(size = 12, face = "bold"))  
  theme(strip.text.y = element_text(size = 12, face = "bold"))   
  theme(aspect.ratio = 5/5)   geom_abline(intercept =0 , slope = 1)

uj5u.com熱心網友回復:

這里至少有兩個復雜的因素。

  1. 使用facet_grid,scales = "free"有點受限:同一列中的圖仍將具有相同的 x 軸,并且同一行中的圖仍將具有相同的 y 軸。一種解決方案是使用facet_wrap,它允許所有刻度相互獨立。

  2. 設定geom_textx=1.5,y=3意味著軸將始終至少延伸這么遠,即使資料的范圍更小——例如,對于您的 RT 資料,其中最大 y 值為 ~0.6。一種解決方案是為資料中的每個方面設定標簽位置,作為該方面范圍的一部分。

library(tidyverse)

Index.labs <- c("RT (s)", "MT (s)", "RSP (s)")
names(Index.labs) <- c("1", "2", "3")

Group.labs <- c("Visible", "Remembered")
names(Group.labs) <- c("Grp_1", "Grp_2")

Cors <- dataLong %>% 
  group_by(Group, Index) %>% 
  summarize(
    text_x = max(Hand) * .1,    # plot text at 10% of x axis
    text_y = max(Eye) * .9,     # & 90% of y axis
    Cor=round(cor(Eye, Hand), 3)
  )

ggplot(dataLong, aes(x = Hand, y = Eye))  
  geom_point()  
  facet_wrap(                   # facet_wrap instead of facet_grid
    vars(Index, Group), 
    ncol = 2,
    scales = "free",
    labeller = labeller(Index = Index.labs, Group = Group.labs)
  ) 
  geom_text(
    aes(x = text_x, y = text_y, label = paste("r =", Cor)), # replace 1.5 & 3 w/ 
    size = 4.5,                                             # text_x & text_y
    hjust = 0,
    data = Cors
  )   
  theme_bw()   
  theme(
    axis.text = element_text(size = 12, face = "bold"),
    axis.title.y = element_text(vjust= 1.8, size = 20),
    axis.title.x = element_text(vjust= -0.5, size = 18),
    axis.title = element_text(face = "bold"),
    strip.text = element_text(size = 12, face = "bold"),
    aspect.ratio = .8     # adjust aspect ratio to allow a bit more width
  )   
  geom_abline()      # intercept=0, slope=1 are defaults, don't need to specify

您可能需要更細粒度的控制——例如,將軸限制設定為在每個范圍內相等Index但讓它們在索引之間變化可能會很好。此時,更容易制作具有不同規格的多個圖,然后使用cowplotor將它們連接在一起patchwork

uj5u.com熱心網友回復:

這是一種替代方法,cowplot用于組合多個圖。這可能需要更多的努力,但會給你更大的控制權。在此示例中,最終繪圖在 的每個級別內具有相同的軸范圍Index,但讓這些在Indexes 之間變化。

library(tidyverse)
library(cowplot)

# since we'll have to generate three plots, we'll put our `ggplot` spec 
# into a function
plot_row <- function(dataLong, Cors) {
  text_x <- max(dataLong$Hand) * .1    # set text position as proportion of 
  text_y <- max(dataLong$Eye) * .9     # subplot range
  p <- ggplot(dataLong, aes(x = Hand, y = Eye))  
    geom_point()  
    facet_grid(
      Index ~ Group, 
      labeller = labeller(Index = Index.labs, Group = Group.labs)
    )  
    geom_text(
      aes(x = text_x, y = text_y, label = paste("r =", Cor)),
      size = 4.5,
      hjust = 0,
      data = Cors
    )   
    coord_fixed(xlim = c(0, NA), ylim = c(0, NA))  
    theme_bw()   
    theme(
      axis.text = element_text(size = 12, face = "bold"),
      axis.title = element_blank(),
      strip.text.y = element_text(size = 12, face = "bold"),
      plot.margin = margin(0,0,0,0)
    )   
    geom_abline()
  # only include column facet labels for the top row
  if ("3" %in% dataLong$Index) {
    p   theme(strip.text.x = element_text(size = 12, face = "bold"))
  } else {
    p   theme(strip.text.x = element_blank())
  }
}

# unchanged from original code
Index.labs <- c("RT (s)", "MT (s)", "RSP (s)")
names(Index.labs) <- c("1", "2", "3")

Group.labs <- c("Visible", "Remembered")
names(Group.labs) <- c("Grp_1", "Grp_2")

Cors <- dataLong %>% group_by(Group,Index) %>% summarize(Cor=round(cor(Eye,Hand),3))

# split data and Cors into three separate dfs each -- one for each level of
# Index -- and pass them to the plotting function
dataLongList <- split(dataLong, dataLong$Index)
CorsList <- split(Cors, Cors$Index)
plot_rows <- map2(dataLongList, CorsList, plot_row)

# use cowplot::plot_grid to assemble the plots, and cowplot::add_sub to 
# add axis labels
p <- plot_grid(plotlist = rev(plot_rows), ncol = 1, align = "vh") %>% 
  add_sub("Hand", fontface = "bold", size = 18) %>% 
  add_sub("Eye", fontface = "bold", size = 18, x = .1, y = 6.5, angle = 90)

# NB, placing the axis labels using `add_sub` is the most finicky part -- the 
# right values of x, y, hjust, and vjust will depend on your plot dimensions and
# margins, and often take trial and error to figure out.

ggsave(“plot.png”, p, width = 5, height = 7.5)

uj5u.com熱心網友回復:

聚類點的呈現總是很棘手,geom_hex()hexbin庫中查看,而不是 geom_point().

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/431999.html

標籤:r ggplot2 纵横比

上一篇:在R中使用sf在世界地圖上對資料進行子集化和繪圖:“錯誤:找不到物件”

下一篇:創建點圖,將點顯示為內圓和外圓,相互在里面,大小與它們的值類似

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • GPU虛擬機創建時間深度優化

    **?桔妹導讀:**GPU虛擬機實體創建速度慢是公有云面臨的普遍問題,由于通常情況下創建虛擬機屬于低頻操作而未引起業界的重視,實際生產中還是存在對GPU實體創建時間有苛刻要求的業務場景。本文將介紹滴滴云在解決該問題時的思路、方法、并展示最終的優化成果。 從公有云服務商那里購買過虛擬主機的資深用戶,一 ......

    uj5u.com 2020-09-10 06:09:13 more
  • 可編程網卡芯片在滴滴云網路的應用實踐

    **?桔妹導讀:**隨著云規模不斷擴大以及業務層面對延遲、帶寬的要求越來越高,采用DPDK 加速網路報文處理的方式在橫向縱向擴展都出現了局限性。可編程芯片成為業界熱點。本文主要講述了可編程網卡芯片在滴滴云網路中的應用實踐,遇到的問題、帶來的收益以及開源社區貢獻。 #1. 資料中心面臨的問題 隨著滴滴 ......

    uj5u.com 2020-09-10 06:10:21 more
  • 滴滴資料通道服務演進之路

    **?桔妹導讀:**滴滴資料通道引擎承載著全公司的資料同步,為下游實時和離線場景提供了必不可少的源資料。隨著任務量的不斷增加,資料通道的整體架構也隨之發生改變。本文介紹了滴滴資料通道的發展歷程,遇到的問題以及今后的規劃。 #1. 背景 資料,對于任何一家互聯網公司來說都是非常重要的資產,公司的大資料 ......

    uj5u.com 2020-09-10 06:11:05 more
  • 滴滴AI Labs斬獲國際機器翻譯大賽中譯英方向世界第三

    **桔妹導讀:**深耕人工智能領域,致力于探索AI讓出行更美好的滴滴AI Labs再次斬獲國際大獎,這次獲獎的專案是什么呢?一起來看看詳細報道吧! 近日,由國際計算語言學協會ACL(The Association for Computational Linguistics)舉辦的世界最具影響力的機器 ......

    uj5u.com 2020-09-10 06:11:29 more
  • MPP (Massively Parallel Processing)大規模并行處理

    1、什么是mpp? MPP (Massively Parallel Processing),即大規模并行處理,在資料庫非共享集群中,每個節點都有獨立的磁盤存盤系統和記憶體系統,業務資料根據資料庫模型和應用特點劃分到各個節點上,每臺資料節點通過專用網路或者商業通用網路互相連接,彼此協同計算,作為整體提供 ......

    uj5u.com 2020-09-10 06:11:41 more
  • 滴滴資料倉庫指標體系建設實踐

    **桔妹導讀:**指標體系是什么?如何使用OSM模型和AARRR模型搭建指標體系?如何統一流程、規范化、工具化管理指標體系?本文會對建設的方法論結合滴滴資料指標體系建設實踐進行解答分析。 #1. 什么是指標體系 ##1.1 指標體系定義 指標體系是將零散單點的具有相互聯系的指標,系統化的組織起來,通 ......

    uj5u.com 2020-09-10 06:12:52 more
  • 單表千萬行資料庫 LIKE 搜索優化手記

    我們經常在資料庫中使用 LIKE 運算子來完成對資料的模糊搜索,LIKE 運算子用于在 WHERE 子句中搜索列中的指定模式。 如果需要查找客戶表中所有姓氏是“張”的資料,可以使用下面的 SQL 陳述句: SELECT * FROM Customer WHERE Name LIKE '張%' 如果需要 ......

    uj5u.com 2020-09-10 06:13:25 more
  • 滴滴Ceph分布式存盤系統優化之鎖優化

    **桔妹導讀:**Ceph是國際知名的開源分布式存盤系統,在工業界和學術界都有著重要的影響。Ceph的架構和演算法設計發表在國際系統領域頂級會議OSDI、SOSP、SC等上。Ceph社區得到Red Hat、SUSE、Intel等大公司的大力支持。Ceph是國際云計算領域應用最廣泛的開源分布式存盤系統, ......

    uj5u.com 2020-09-10 06:14:51 more
  • es~通過ElasticsearchTemplate進行聚合~嵌套聚合

    之前寫過《es~通過ElasticsearchTemplate進行聚合操作》的文章,這一次主要寫一個嵌套的聚合,例如先對sex集合,再對desc聚合,最后再對age求和,共三層嵌套。 Aggregations的部分特性類似于SQL語言中的group by,avg,sum等函式,Aggregation ......

    uj5u.com 2020-09-10 06:14:59 more
  • 爬蟲日志監控 -- Elastc Stack(ELK)部署

    傻瓜式部署,只需替換IP與用戶 導讀: 現ELK四大組件分別為:Elasticsearch(核心)、logstash(處理)、filebeat(采集)、kibana(可視化) 下載均在https://www.elastic.co/cn/downloads/下tar包,各組件版本最好一致,配合fdm會 ......

    uj5u.com 2020-09-10 06:15:05 more
最新发布
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:33:24 more
  • MySQL中binlog備份腳本分享

    關于MySQL的二進制日志(binlog),我們都知道二進制日志(binlog)非常重要,尤其當你需要point to point災難恢復的時侯,所以我們要對其進行備份。關于二進制日志(binlog)的備份,可以基于flush logs方式先切換binlog,然后拷貝&壓縮到到遠程服務器或本地服務器 ......

    uj5u.com 2023-04-20 08:28:06 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:27:27 more
  • 快取與資料庫雙寫一致性幾種策略分析

    本文將對幾種快取與資料庫保證資料一致性的使用方式進行分析。為保證高并發性能,以下分析場景不考慮執行的原子性及加鎖等強一致性要求的場景,僅追求最終一致性。 ......

    uj5u.com 2023-04-20 08:26:48 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:26:35 more
  • 云時代,MySQL到ClickHouse資料同步產品對比推薦

    ClickHouse 在執行分析查詢時的速度優勢很好的彌補了MySQL的不足,但是對于很多開發者和DBA來說,如何將MySQL穩定、高效、簡單的同步到 ClickHouse 卻很困難。本文對比了 NineData、MaterializeMySQL(ClickHouse自帶)、Bifrost 三款產品... ......

    uj5u.com 2023-04-20 08:26:29 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:25:13 more
  • Redis 報”OutOfDirectMemoryError“(堆外記憶體溢位)

    Redis 報錯“OutOfDirectMemoryError(堆外記憶體溢位) ”問題如下: 一、報錯資訊: 使用 Redis 的業務介面 ,產生 OutOfDirectMemoryError(堆外記憶體溢位),如圖: 格式化后的報錯資訊: { "timestamp": "2023-04-17 22: ......

    uj5u.com 2023-04-20 08:24:54 more
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:24:03 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:23:11 more