如何解决带有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)
解决方法
您将需要在$ 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()
输出:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。