仅在GGR绘图的geom_文本的标签上添加颜色
我试着只在标签上涂上颜色 此代码正在运行仅在GGR绘图的geom_文本的标签上添加颜色,r,ggplot2,colors,label,geom-text,R,Ggplot2,Colors,Label,Geom Text,我试着只在标签上涂上颜色 此代码正在运行 ggplot(cmd2, aes(V1, V2)) + geom_point(mapping = aes(x = V1, y = V2,shape=Treatment, color=Concentration), size=2) + scale_color_gradient(low = "blue", high = "red")+ coord_fixed() + geom_segment(d
ggplot(cmd2, aes(V1, V2)) + geom_point(mapping = aes(x = V1, y = V2,shape=Treatment, color=Concentration), size=2) + scale_color_gradient(low = "blue", high = "red")+
coord_fixed() +
geom_segment(data = vec.sp.df,
aes(x = 0, xend = V1, y = 0, yend = V2),
arrow = arrow(length = unit(0.01, "mm")), colour = "grey") +
geom_text(data = vec.sp.df, aes(x = V1, y = V2, label = ASV),size = 3)+
geom_label_repel(aes(label = Sample), size=2.5, label.size = NA, fill = NA, colour = "grey")
但是当我在geom_文本上添加列表以添加颜色时,我得到了这个错误
legend_final <- as.vector(as.character(df_legend$phylum))
ggplot(cmd2, aes(V1, V2)) + geom_point(mapping = aes(x = V1, y = V2,shape=Treatment, color=Concentration), size=2) + scale_color_gradient(low = "blue", high = "red")+
coord_fixed() +
geom_segment(data = vec.sp.df,
aes(x = 0, xend = V1, y = 0, yend = V2),
arrow = arrow(length = unit(0.01, "mm")), colour = "grey") +
geom_text(data = vec.sp.df, aes(x = V1, y = V2, label = ASV, colour = legend_final),size = 3)+
geom_label_repel(aes(label = Sample), size=2.5, label.size = NA, fill = NA, colour = "grey")
Error
Error: Discrete value supplied to continuous scale
legend_final问题是,首先要将连续变量(浓度)映射到颜色上,而在geom_文本中,现在要将离散变量映射到颜色上。你不能两者兼得。默认情况下,只有一个颜色比例,它是连续的还是离散的。如果您想要另一个色阶,请查看ggnewscale
软件包。