R ggplot2未在图例值中指定颜色

R ggplot2未在图例值中指定颜色,r,ggplot2,colors,legend,R,Ggplot2,Colors,Legend,我为绘图生成了以下代码: ggplot(Table_Final_v0, aes(x=log2(SeqCount_a+1), y=log2(SeqCount_m1+1), fill=kingdom2, color=Color_point2)) + geom_point(size=Size_point, alpha=0.8, color=Color_point2) + scale_color_manual(values = Color_point2) + theme_classic() +

我为绘图生成了以下代码:

ggplot(Table_Final_v0, aes(x=log2(SeqCount_a+1), y=log2(SeqCount_m1+1), fill=kingdom2, color=Color_point2)) + 
  geom_point(size=Size_point, alpha=0.8, color=Color_point2) + scale_color_manual(values = Color_point2) +
  theme_classic() + ylab("log2(Sequence Count -m 1)\n") + xlab("\nlog2(Sequence Count -a)") + ylim(0,14) + xlim(7,17) + 
  geom_text(label=species, nudge_x = -0.5, nudge_y = 0.5, check_overlap = T, show.legend = F, color="black") +
  theme(axis.text.x = element_text(size=10), axis.title=element_text(size=12), 
        axis.text.y =element_text(size=10),plot.margin = margin(1, 0.5, 0.5, 1, "cm")) + ggtitle(title) +
  theme(plot.title = element_text(size = 14)) + theme(legend.title=element_blank())
这将生成以下绘图:

表_Final _v0如下所示:

rRNA                 Seq_count_m1 Seq_count_a  Size_point    species      kingdom2    Color_point2
Loxodonta_africana            178       18722          6         Laf      Elephant          red3
Acyrthosiphon_pisum             0       50324          4         Api       Insects   dodgerblue3
Aedes_aegypti                   0       36776          4         Aae       Insects   dodgerblue3
Aegilops_tauschii              26       17539          4         Ata        Plants   forestgreen
      .                         .           .          .         .           .        .  
      .                         .           .          .         .           .        .
如您所见,
kingdom2
变量包含图例中显示的名称,
Color\u point2
变量包含我希望在绘图和图例中显示的颜色。但不知何故,我无法将它们分配给传说,它们只出现在情节中


代码有什么问题?我希望在图例中的每个标签上也显示颜色,就像使用
scale\u color\u manual

一样,这可能是实现您的任务的一个选项

ggplot(df, aes(x=log2(Seq_count_a+1), y=log2(Seq_count_m1+1), color=kingdom2)) + 
  geom_point(size=df$Size_point, alpha=0.8) +
  scale_fill_manual(values = df$Color_point2) +
  theme_classic() + 
  ylab("log2(Sequence Count -m 1)\n") + 
  xlab("\nlog2(Sequence Count -a)") + 
  ylim(0,14) + 
  xlim(7,17) + 
  geom_text(label=df$species, nudge_x = -0.5, nudge_y = 0.5, check_overlap = T, show.legend = F, color="black") +
  theme(axis.text.x = element_text(size=10), 
        axis.title.x = element_text(size=12), 
        axis.text.y = element_text(size=10), 
        plot.margin = margin(1, 0.5, 0.5, 1, "cm"),
        legend.title=element_blank()
        )

数据:


df

df <- tribble(
~rRNA,                 ~Seq_count_m1, ~Seq_count_a,  ~Size_point,    ~species,      ~kingdom2,    ~Color_point2,
"Loxodonta_africana",  178,   18722, 6,    "Laf",  "Elephant", "red3", 
"Acyrthosiphon_pisum", 0,     50324, 4,    "Api",  "Insects",  "dodgerblue3", 
"Aedes_aegypti",       0,     36776, 4,    "Aae",  "Insects",  "dodgerblue3", 
"Aegilops_tauschii",   26,    17539, 4,    "Ata",  "Plants",   "forestgreen")