pfacet<-function(data,x,y){
ggplot(data, aes_string(x=x, y=y)) +
stat_density2d(aes(fill=..level..,contour=TRUE), geom="density2d",color="black") +
geom_smooth(method=lm, se=FALSE,color="black") +
facet_wrap(~id)+
theme_bw()+
theme(panel.grid.major = element_line(colour = "#808080"))+
guides(fill=FALSE)
}
绘图
pfacet(data=df,x='log(area)',y='log(fd)')+
ggsave('test.png',width=6, height=4,dpi=300)
但是 ,我想将这些回归线移到每个方面的最高值。即使其成为包络线。例如。 http://specialpapers.gsapubs.org/content/401/63/F11.large.jpg
通常情况下,我只是制作一条回归线并将其移位,但我不知道如何在一个方面做到这一点。你能指点一下吗?
数据
dput(droplevels(head(df, 100)))
structure(list(fd = c(11, 7.75, 55.25, 45.25, 9.5, 89, 14.5,
8, 84.25, 5.25, 79.5, 7.75, 71, 38.5, 242.25, 33, 32, 19, 58.5,
249.25, 19, 72.5, 6.25, 27.0333333333333, 26.5, 81, 30, 29, 39.75,
18.5, 64.25, 91, 4.5, 30.5, 74, 256.75, 9, 81, 27, 7.5, 107,
26.75, 47.25, 16, 57, 37, 48.25, 48, 36, 147.25), area = c(20168.2374,
432.528, 5780.8535, 1411.5435, 543.8975, 660.447, 24995.9752,
543.8975, 2659.9178, 277.1287, 147.8883, 153.0683, 2217.0298,
1188.8045, 4237.2205, 489.5078, 1051.5352, 1362.3337, 1401.1836,
169.3852, 1333.8439, 1051.5352, 29.5259, 1429.6734, 668.2169,
17068.0216, 660.447, 16860.8226, 116.5495, 3820.2325, 784.7664,
841.7461, 1696.4422, 85.9876, 2066.8105, 2090.1204, 121.7294,
9999.9441, 127.4274, 1152.5447, 934.9857, 1424.4935, 1774.1419,
543.8975, 784.7664, 237.5019, 3486.124, 1080.025, 6164.1717,
3348.8546), id = structure(c(3L, 2L, 2L, 4L, 4L, 3L, 4L, 4L,
4L, 4L, 4L, 4L, 3L, 4L, 3L, 3L, 3L, 4L, 3L, 1L, 3L, 4L, 4L, 4L,
4L, 4L, 3L, 3L, 4L, 4L, 3L, 4L, 4L, 3L, 4L, 4L, 4L, 4L, 4L, 3L,
3L, 4L, 2L, 4L, 3L, 4L, 4L, 3L, 4L, 3L), .Label = c("Csb", "Dfb(E)",
"Dfa", "Cfa"), class = "factor")), .Names = c("fd", "area", "id"
), row.names = c("65775", "61848", "11286", "22467", "34601",
"53841", "14661", "8941", "88607", "47681", "7898", "9598", "40615",
"35550", "70985", "64634", "43864", "88065", "37520", "100794",
"74916", "76759", "48928", "17575", "7424", "30848", "53970",
"65662", "27392", "82248", "48004", "93560", "51147", "42321",
"30070", "22096", "25575", "49067", "23702", "65877", "53617",
"90727", "59449", "34568", "48155", "96101", "31358", "40150",
"75458", "71566"), class = "data.frame")
> dput(droplevels(head(ddf2, 100)))
structure(list(fd = c(11, 7.75, 55.25, 45.25, 9.5, 89, 14.5,
8, 84.25, 5.25, 79.5, 7.75, 71, 38.5, 242.25, 33, 32, 19, 58.5,
249.25, 19, 72.5, 6.25, 27.0333333333333, 26.5, 81, 30, 29, 39.75,
18.5, 64.25, 91, 4.5, 30.5, 74, 256.75, 9, 81, 27, 7.5, 107,
26.75, 47.25, 16, 57, 37, 48.25, 48, 36, 147.25, 23.5, 42, 1.08333333333333,
21.5, 6.51666666666667, 198, 47.5, 8.75, 16, 43.5, 34.75, 30.25,
132.25, 2.25, 12.5, 225, 37, 17.25, 63.5, 48, 19.75, 12, 62.5,
64, 27, 11, 72.25, 246, 27.75, 15.5, 178, 93.75, 3.75, 3, 46.25,
4, 6.25, 5.25, 20, 44, 44.5, 1, 33, 18.25, 14.5, 29.25, 9, 33,
133, 67), area = c(20168.2374, 432.528, 5780.8535, 1411.5435,
543.8975, 660.447, 24995.9752, 543.8975, 2659.9178, 277.1287,
147.8883, 153.0683, 2217.0298, 1188.8045, 4237.2205, 489.5078,
1051.5352, 1362.3337, 1401.1836, 169.3852, 1333.8439, 1051.5352,
29.5259, 1429.6734, 668.2169, 17068.0216, 660.447, 16860.8226,
116.5495, 3820.2325, 784.7664, 841.7461, 1696.4422, 85.9876,
2066.8105, 2090.1204, 121.7294, 9999.9441, 127.4274, 1152.5447,
934.9857, 1424.4935, 1774.1419, 543.8975, 784.7664, 237.5019,
3486.124, 1080.025, 6164.1717, 3348.8546, 236.2069, 510.2277,
31.5979, 916.8558, 1994.2908, 3501.6639, 1152.5447, 486.9178,
533.5376, 271.9488, 336.6985, 1103.3349, 9764.2552, 36.7778,
2375.0191, 512.8176, 422.1681, 859.8761, 1118.8749, 237.5019,
133.6434, 453.2479, 1787.0918, 6063.1622, 237.5019, 1383.0537,
668.2169, 1424.4935, 621.5971, 1486.6532, 7355.5662, 984.1955,
68.8937, 154.6223, 116.5495, 1665.3624, 43.5118, 450.6579, 510.2277,
1494.4231, 404.0381, 598.2873, 339.2884, 12406.043, 274.5387,
151.2553, 753.6865, 29059.6666, 3470.5841, 1885.5113), id = structure(c(3L,
2L, 2L, 4L, 4L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 4L, 3L, 3L, 3L,
4L, 3L, 1L, 3L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 4L, 4L, 3L, 4L, 4L,
3L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 4L, 2L, 4L, 3L, 4L, 4L, 3L, 4L,
3L, 4L, 4L, 4L, 3L, 4L, 3L, 3L, 4L, 3L, 4L, 4L, 3L, 4L, 4L, 4L,
4L, 4L, 2L, 3L, 4L, 2L, 3L, 4L, 4L, 4L, 4L, 4L, 3L, 4L, 3L, 2L,
1L, 4L, 2L, 4L, 2L, 4L, 2L, 4L, 4L, 4L, 4L, 3L, 4L, 4L, 3L, 4L,
2L, 2L, 4L), .Label = c("Csb", "Dfb(E)", "Dfa", "Cfa"), class = "factor")), .Names = c("fd",
"area", "id"), row.names = c("65775", "61848", "11286", "22467",
"34601", "53841", "14661", "8941", "88607", "47681", "7898",
"9598", "40615", "35550", "70985", "64634", "43864", "88065",
"37520", "100794", "74916", "76759", "48928", "17575", "7424",
"30848", "53970", "65662", "27392", "82248", "48004", "93560",
"51147", "42321", "30070", "22096", "25575", "49067", "23702",
"65877", "53617", "90727", "59449", "34568", "48155", "96101",
"31358", "40150", "75458", "71566", "1687", "86603", "77451",
"68075", "14478", "69151", "66028", "77394", "68580", "16328",
"26945", "73615", "24179", "19497", "82448", "25098", "23565",
"8113", "66312", "96062", "60313", "34767", "97877", "48598",
"96135", "36877", "7309", "71065", "49622", "65051", "55340",
"105109", "26480", "4550", "18935", "61714", "31667", "55035",
"27563", "17332", "35694", "20092", "44334", "21344", "22303",
"64816", "12814", "12391", "52770", "84979"), class = "data.frame")