labeling points with legend

62 views
Skip to first unread message

Darío Suárez Gracia

unread,
Mar 22, 2010, 2:52:06 PM3/22/10
to ggplot2
Hello,
I'm a newbie with ggplot2. I have problems generating a scatterplot
in which each point is labeled with an ID(number, letter, ...) and the
legend includes the ID and the name of each point. Shapes could be a
good choice but I don't know how to extend them to more than 6
choices.

The used data looks as follows
benchmark IPC dl1.mpki dl2.mpki dl3.mpki
1 400.perlbench 1.8233 11.7052 0.1550 0.0564
2 401.bzip2 1.1567 64.4849 12.8893 10.8238
3 403.gcc 1.5815 14.9741 2.0674 0.3860
4 410.bwaves 2.0622 54.4960 2.2584 2.9829
5 416.gamess 2.5907 1.2177 0.0018 0.0012

but includes up to 50 rows. With:
ggplot(data, aes(IPC, dl1.mpki)) + geom_text(aes(label=1:27), size =
3, angle=60)

It shows an ID in every point but I'm unable to generate a legend
like:
1 400.perlbench
2 401.bzip2

Any idea would be really appreciated.

Thanks in advance for your help,
Darío

takahashi kohske

unread,
Mar 23, 2010, 12:27:30 PM3/23/10
to Darío Suárez Gracia, ggplot2
Hi,

maybe I cannot understand what you want to do, but please try:

ggplot(data[1:5,], aes(IPC,
dl1.mpki))+geom_text(aes(label=paste(1:5,d$benchmark)),size=3,angle=60)

HTH.

2010/3/23 Darío Suárez Gracia <dariosua...@gmail.com>:

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2
>
> To unsubscribe from this group, send email to ggplot2+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
>

Xie Chao

unread,
Mar 23, 2010, 1:29:02 PM3/23/10
to takahashi kohske, Darío Suárez Gracia, ggplot2
Hi Dario,

If I understand you correctly, you want to use numbers or letters to
annotate data points on the plot, and then use legend to explain the
meaning of the number or letters?

df <- data.frame(x=rnorm(5), y=rnorm(5), name=paste('name', letters[1:5]))
qplot(x,y, data=df) +
geom_point(aes(x+0.06, shape=name), size=3) +
scale_shape_manual(values = as.character(as.numeric(df$name)))

Or if you have more than 10 data points, replace the last statement with
scale_shape_manual(values = letters[df$name])

I am not sure how to make this (annotation + legend) work for more
than 36 data points, but isn't a 37-row legend too big for a plot?

Xie Chao

2010/3/24 takahashi kohske <takahash...@gmail.com>:

Darío Suárez Gracia

unread,
Mar 23, 2010, 2:57:54 PM3/23/10
to Xie Chao, takahashi kohske, ggplot2
Hi all,
Thank you very much for your help, especially Xie Chao. Your example
is what I was looking for because we have less than 30 points.

Best regards,
Darío

Reply all
Reply to author
Forward
0 new messages