Sve*_*ito 5 r ggplot2 facet-wrap facet-grid
我正在努力让每个面板都有facet_grid自己的 y 轴。
所以基本上我希望该图的所有子图都有自己的 y 轴(以便您实际上可以看到数据)。同时,我希望每列都有一个固定的 x 轴,就像现在一样。条带标签也应该像现在这样。
\n\n\n\n我尝试使用facet_wrap它,这确实会给每个面板自己的 y 轴。但后来我很难修复每列的 x 轴。scales="free_y"修复所有面板中的 x 轴,而不是像 中那样每列facet_grid。另外,我得到strip labels了每个子图,这也是我不想要的。
。
\n\n\n\n这是我与一些示例数据一起使用的代码的相关部分,这些数据应该足以构建非常相似的图:
\n\nBAAM = data.frame(Subject = rep(c("S1", "S2", "S3", "S4"), each=4),\n Feature = rep(c("Maximum negative\\namplitude [\xc2\xb5V]", "Duration [sec]", "Descending\\nslope [\xc2\xb5V/sec]", "Ascending\\nslope [\xc2\xb5V/sec]"), times=4),\n mean = c(-200, 1, 1500, 1600, -210, 1.1, 1300, 1500, -250, 3, 1400, 1600, -50, 0.5, 1000, 1000),\n dif = c(20, 0.1, 200, 300, 10, -0.3, -100, 400, 30, 0.4, -200, -200, -20, 0.6, 300, 400))\n\nlibrary(ggplot2)\nggplot(BAAM, aes(x=mean, y=dif)) + \n geom_point() + \n # facet_grid(rows=vars(Subject), cols=vars(Feature), scales = "free", switch="both") +\n facet_wrap(Subject+Feature~ ., scales="free_y", ncol = 4, strip.position = "bottom") + \n theme_minimal() +\n ggtitle("Slow Wave Characteristics - Bland Altman plot") +\n annotate("segment", x=-Inf, xend=Inf, y=-Inf, yend=-Inf)+\n annotate("segment", x=-Inf, xend=-Inf, y=-Inf, yend=Inf)+ \n theme(text = element_text(size = 20),\n axis.title.x = element_blank(),\n axis.title.y = element_blank(),\n legend.title = element_blank(),\n axis.text.x = element_text(angle = 45, hjust=1),\n panel.spacing = unit(2, "lines"),\n strip.placement = "outside",\n strip.switch.pad.wrap = unit(0, "lines"))\nRun Code Online (Sandbox Code Playgroud)\n\n如果这篇文章是重复的文章,我很高兴被推荐到相应的帖子。不过,我已经做了广泛的研究。我发现了非常相关的问题,但没有一个完全尝试解决我遇到的完全相同的问题。我非常感谢你的帮助。
\n\n感谢@s_t,我发现了lemon具有该facet_rep_grid功能的包。这仍然不是我想要的,但更接近了一步。现在所有子图的轴都可见,但每行的 y 限制仍然相同。我希望每个面板/子图的 y 限制都是单独的。
library(lemon)\nfacet_rep_grid(rows=vars(Subject), cols=vars(Feature), scales = "free", switch="both", repeat.tick.labels = \'y\')\nRun Code Online (Sandbox Code Playgroud)\n\n\n