R 带有geom_文字和geom_点的颜色图例
图例标签旁边的点如何着色?缩放颜色手动或缩放填充手动不起作用。另外,如何将图例中的点更改为正方形?谢谢R 带有geom_文字和geom_点的颜色图例,r,ggplot2,legend,ggrepel,geom-point,R,Ggplot2,Legend,Ggrepel,Geom Point,图例标签旁边的点如何着色?缩放颜色手动或缩放填充手动不起作用。另外,如何将图例中的点更改为正方形?谢谢 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),colo
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)
set.seed(1)
图书馆(GG2)
图书馆(ggrepel)
df您需要在geom_point()
,设置color=l
中的美学调用中包含color参数。然后您可以使用scale\u color\u manual
使用所需的颜色
p_vol <- ggplot(df, aes(n, y, label = l)) +
geom_point(aes(fill=l, color = l)) +
geom_text_repel(col=df$col) +
theme_classic() +
scale_color_manual(values = df$col)
p\u vol您需要在geom\u point()
中的美学调用中包含颜色参数,设置color=l
。然后您可以使用scale\u color\u manual
使用所需的颜色
p_vol <- ggplot(df, aes(n, y, label = l)) +
geom_point(aes(fill=l, color = l)) +
geom_text_repel(col=df$col) +
theme_classic() +
scale_color_manual(values = df$col)
p\u vol您还可以尝试使用数据框中的颜色从aes()
启用fill
。这里是代码,我使用了不同的颜色,因为我对函数调色板没有足够的了解。还可以使用scale\u fill\u identity()。代码如下:
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()
set.seed(1)
图书馆(GG2)
图书馆(ggrepel)
图书馆(RColorBrewer)
df您还可以尝试使用数据框中的颜色从aes()
启用fill
。这里是代码,我使用了不同的颜色,因为我对函数调色板没有足够的了解。还可以使用scale\u fill\u identity()。代码如下:
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()
set.seed(1)
图书馆(GG2)
图书馆(ggrepel)
图书馆(RColorBrewer)
df不建议调用ggplot
中带有df$
的列。建议将col
列重命名为colors
或其他非参数。不建议在ggplot
中调用带有df$
的列。建议将col
列重命名为colors
或其他非参数。我发现填充是不必要的,事实上scale\u fill\u identity()即使没有填充,也使用标准的ggplot颜色,而不是数据框中的颜色。我发现填充是不必要的,事实上scale\u fill\u identity()即使没有填充,也使用标准ggplot颜色,而不是数据框中的颜色