ggplot中的多字符绘图形状

hal*_*ass 5 r ggplot2

说这是我的数据集:

> ( fake = data.frame( id=as.character(18:22), x=rnorm(5), y=rnorm(5) ) )

  id           x           y
1 18  1.93800377  0.67515777
2 19  1.28241814 -0.04164806
3 20 -1.58919444 -0.50885536
4 21 -0.08127943 -1.90003188
5 22  0.78134213  0.17693039
Run Code Online (Sandbox Code Playgroud)

我想要一个x对比的散点图,y其中绘图形状是id变量.我试过这个:

ggplot( data=fake, aes( x=x, y=y, shape=id) ) + geom_point() +
  scale_shape_manual(values=as.character(fake$id)) + theme_bw()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

似乎只有第一个字符id被用作绘图形状.我怎样才能使用整个字符串?

MrF*_*ick 8

如果要在绘图上打印文本,请使用geom_text而不是geom_point

ggplot( data=fake, aes( x=x, y=y, label=id) ) + geom_text() + theme_bw()
Run Code Online (Sandbox Code Playgroud)

geom_point使用的绘图字符(形状)只能是单个字符.对于较长的字符串,您必须使用geom_text().

在此输入图像描述