带有geom_text_repel和geom_point的颜色图例

图例标签旁边的点如何着色? scale_color_manual或scale_fill_manual不起作用。另外,如何将图例中的点更改为正方形?谢谢

set.seed(1)
library(ggplot2)
library(ggrepel)
df <- data.frame(n=runif(8),y=1:8,l=letters[1:8],col=palette.colors(8))

p_vol <- ggplot(df,aes(n,y,label = l)) +
  geom_point(aes(fill=l),color = df$col) +
  geom_text_repel(col=df$col)+theme_classic()
print(p_vol)

带有geom_text_repel和geom_point的颜色图例

iCMS 回答:带有geom_text_repel和geom_point的颜色图例

您将需要在$ readarray -t array < <(echo "dGVzdA==" | base64 -d | xxd -p -c1) $ declare -p array declare -a array=([0]="74" [1]="65" [2]="73" [3]="74") 的美学调用中包括color参数,并设置geom_point()。然后,您可以使用color = l使用所需的颜色。

scale_color_manual
,

您还可以尝试使用数据框中的颜色从fill中启用aes()。在此代码中,我使用了不同的颜色,因为我对您以前拥有颜色的函数palette.colors的了解不足。同样使用scale_fill_identity()可以直接从数据变量(在fill中定义的变量)获取颜色。这里的代码:

set.seed(1)
library(ggplot2)
library(ggrepel)
library(RColorBrewer)
df <- data.frame(n=runif(8),y=1:8,l=letters[1:8],col=rainbow(8))
#Plot
ggplot(df,aes(n,y,label = l,color=l,fill=col)) +
  geom_point() +
  geom_text_repel(show.legend = F)+theme_classic()+
  scale_fill_identity()

输出:

enter image description here

本文链接:https://www.f2er.com/1516521.html

大家都在问