R 如何替换ggplot2中的图例键?

R 如何替换ggplot2中的图例键?,r,ggplot2,legend,R,Ggplot2,Legend,我在这个散点图中使用了图片的数字作为数据点,它是用ggplot2创建的。因此,图例键为“a”。相反,我需要标签旁边的普通点(也用簇着色)。我怎么能意识到这一点?我使用了以下代码: ggplot(data, aes(x=vx, y=vy, color=Cluster, shape=Cluster)) + geom_text(aes(label=PicNr), size =6, fontface = "bold", check_overlap = T, show.legend=T) +

我在这个散点图中使用了图片的数字作为数据点,它是用ggplot2创建的。因此,图例键为“a”。相反,我需要标签旁边的普通点(也用簇着色)。我怎么能意识到这一点?我使用了以下代码:

ggplot(data, aes(x=vx, y=vy, color=Cluster, shape=Cluster)) + geom_text(aes(label=PicNr),
  size =6, fontface = "bold",
  check_overlap = T,
  show.legend=T) +
  theme_bw(base_size = 20)+
  theme(legend.position="top") 
谢谢你的帮助


为此,您可以执行以下操作

library(ggplot2)

ggplot(mtcars, aes(mpg, wt))+
  geom_text(aes(label = cyl, color = factor(cyl)), show.legend = FALSE)+
  geom_point(aes(color = factor(cyl)), alpha = 0)+
  guides(color = guide_legend(override.aes = list(alpha = 1, size = 4)))

因此,您的代码将如下所示:

ggplot(data, aes(x=vx, y=vy, shape=Cluster)) + 
  geom_text(aes(label=PicNr, color=Cluster), size =6, fontface = "bold", check_overlap = T, show.legend=F) +
  geom_point(aes(color=Cluster), alpha = 0)+
  theme_bw(base_size = 20)+
  theme(legend.position="top")+
  guides(color = guide_legend(override.aes = list(alpha = 1, size = 4)))

由(v0.2.0)于2018年8月18日创建。

非常感谢您的支持!我很感激。我在辅助线中添加了形状#19-现在所有图例键都具有相同的形状:辅助线(颜色=辅助线#图例(override.aes=list(alpha=1,size=4,shape=19)))