小编Dav*_*vid的帖子

使用 ggnewscale::new_scale() 和 R 中的 ggplot2 将图例拆分为图中的两列或多列

在遵循 Stefan 对这篇文章的非常有用的回答(他使用的地方)之后ggnewscale::new_scale(),我现在遇到了以下问题:

“如何将自定义图例排列成ggnewscale多个垂直列?” 就像通常使用 ggplot2 中的命令完成的那样guides(scale_shape_manual=guide_legend(ncol=2))

最小可重现示例:

# fictional data in the scheme of /sf/ask/4676314121/

mutated <- list()
for(i in 1:10) {
  mutated[[i]] <- data.frame(Biological.Replicate = rep(1,4),
                           Reagent.Conc = c(10000, 2500, 625, 156.3),
                           Reagent = rep(1,8),
                           Cell.type = rep(LETTERS[i],4),
                           Mean.Viable.Cells.1 = rep(runif(n = 10, min = 0, max = 1),4))
}
mutated <- do.call(rbind.data.frame, mutated)
Run Code Online (Sandbox Code Playgroud)

用户“stefan”回答后修改后的代码如下所示:

# from /sf/answers/4676602661/

library(ggplot2)
library(ggnewscale)
library(dplyr)
library(magrittr)

mutated <- mutated %>% 
  mutate(Cell.type = as.factor(Cell.type),
         Reagent = …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 ggnewscale

5
推荐指数
1
解决办法
1357
查看次数

标签 统计

ggnewscale ×1

ggplot2 ×1

r ×1