小编K. *_*rya的帖子

如何在ggplot的嵌套循环中为跨图中的因子分配相同的颜色?

我正在尝试使用 scale_fill_manual 将相应的颜色分配给嵌套 for 循环中许多图中的因子。然而,结果图最终都是黑色的。

我的整体循环如下:

for(i in seq(from=0, to=100, by=10)){
   for{j in seq(from=0, to=100, by=10)){
       print(ggplot(aes(x , y), data = df)+
        geom_point(inherit.aes = FALSE,data = subset(df,factor_x==i&factor_y==j), aes(x, y, size=point,color=Group))+
        theme_bw()}}
Run Code Online (Sandbox Code Playgroud)

我正在尝试为“分组”中的每个因素分配其自己绘制的一致颜色。我试过使用:

col<-colorRampPalette(brewer.pal(9,"Set1"))(16)
Run Code Online (Sandbox Code Playgroud)

然后我将每种颜色分配给“组”中的特定因素。

但是,在嵌套循环中使用 scale manual 时,因子根本没有颜色。

for(i in seq(from=0, to=100, by=10)){
   for{j in seq(from=0, to=100, by=10)){
       print(ggplot(aes(x , y), data = df)+
        geom_point(inherit.aes = FALSE,data = subset(df,factor_x==i&factor_y==j), aes(x, y, size=point))+
        theme_bw()+scale_fill_manual(values=col)}}
Run Code Online (Sandbox Code Playgroud)

如何在循环中生成的许多图中为“组”中的分类值集成配色方案?

plot r subset nested-loops ggplot2

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

标签 统计

ggplot2 ×1

nested-loops ×1

plot ×1

r ×1

subset ×1