我正在尝试使用 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)
如何在循环中生成的许多图中为“组”中的分类值集成配色方案?