shapes do not match legend

24 views
Skip to first unread message

Wade Wall

unread,
Sep 8, 2009, 12:22:09 PM9/8/09
to ggp...@googlegroups.com
Hi all,

I am just starting with ggplot2, so forgive me if I am asking a stupid
question. I have a data set that I am plotting as a scatter plot and
I have created a legend with symbols for each of the points based on a
priori classification into one of 6 groups, which I have as a column
in the data set. However, the fifth symbol, a square with and x
inside it, plots with either an x inside or a circle. Is this an
error, or is it providing addition information not in the legend? If
it is not an error, how does one make the symbol consistent.

Thanks for any help,

Wade

hadley wickham

unread,
Sep 8, 2009, 12:43:27 PM9/8/09
to Wade Wall, ggp...@googlegroups.com
Hi Wade,

Could you please provide a reproducible example?

Thanks,

Hadley
--
http://had.co.nz/

Wade Wall

unread,
Sep 8, 2009, 1:07:32 PM9/8/09
to hadley wickham, ggp...@googlegroups.com
Sure, I should have done that the first time.

State<-c("A", "A", "A", "A", "A",
"B", "B", "B", "B", "B", "C", "C", "C", "C", "C", "D", "D", "D",
"D", "D", "E", "E", "E", "E", "E", "F", "F", "F", "F", "F")
axis1<-c(0.00973891633387895, -0.000763341029921786,
-0.0124691578471196, 0.00540108210684526, 0.00700929893782788,
0.0153610216374370, -0.00279519575649649, 0.00448919368158433,
0.0124612343960445, 0.00748222389521799, 0.0197001595990201,
-0.00113581177602438, -0.0103258129875896, 0.0175321475737747,
0.00515905881618228, 0.00182866834467452, 0.00595293085243966,
-0.00056103920487429, -0.00641453104154934, -0.00671065452188698,
-0.00558131349869967, -0.0048667919382154, -0.0153960955799779,
-0.0098287584511638, -0.0104631345271171, 0.00361571019710817,
0.0103336338814978, -0.0248333906578573, 0.00333159476054497,
0.00140252320682854)
axis2<-c(0.0183793116612399, 0.00733723736346554,
0.0039088512450552, 0.0120960467989771, -0.0090942056184101,
-0.00533276703111312, 0.00140529701901901, -0.00335917083957771,
-0.00384279007431122, -0.0142395386383838, 0.00791384686231386,
0.0106930421173523, -0.000556666315473373, -0.0121361753441753,
-0.0113675846706736, 0.00294259172566419, 0.00312038117584983,
-0.000788787927436407, 0.00519333584264411, 0.00130305142884046,
-0.00547306424740097, -0.00366546137888452, 0.00322965812079516,
0.0092977992768888, -0.00477462201240453, 0.00792523165506565,
-0.00674447238643132, -0.00354267164256563, 0.00191880984936415,
-0.000702700387329246)
tmp.dat<-data.frame(State,axis1,axis2)
colnames(tmp.dat)<-c("State","Axis1","Axis2")
mds.plot<-qplot(tmp.dat[,2],tmp.dat[,3],data=tmp.dat,shape=tmp.dat[,1])
mds.plot+labs(x="axis 1",y="axis 2",shape="State")

If I run the above code, I get different symbols for the "E" state category.

Thanks for any help.

Wade

hadley wickham

unread,
Sep 12, 2009, 11:41:20 AM9/12/09
to Wade Wall, ggp...@googlegroups.com
Hi Wade,

It looks ok to me. What graphics device are you using?

Hadley
--
http://had.co.nz/

Juliet Hannah

unread,
Sep 12, 2009, 1:19:37 PM9/12/09
to Wade Wall, ggp...@googlegroups.com
I got the same result as Wade at first. I'm on XP. I tried again, but
saved the plot as a PDF -- ggsave("wade.pdf") --and everything came
out fine. What comes up from R
is different from what is saved as a PDF. If I save it as an emf, it
resembles the
incorrect plot. I'm also attaching the pdf. Is it in my head, or are
the symbols for E
not quite the same. This is not a big deal at all, but just wanted to
point it out.


R version 2.9.2 (2009-08-24)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] grid stats graphics grDevices utils datasets
methods base

other attached packages:
[1] ggplot2_0.8.3 reshape_0.8.3 plyr_0.1.9 proto_0.3-8

loaded via a namespace (and not attached):
[1] tools_2.9.2
wades plot.pdf
wade.emf

hadley wickham

unread,
Sep 12, 2009, 3:06:45 PM9/12/09
to Juliet Hannah, Wade Wall, ggp...@googlegroups.com
It sounds like a platform specific rendering issue, and unfortunately
there's not much I can do about that.

Hadley
--
http://had.co.nz/

Wade Wall

unread,
Sep 14, 2009, 9:59:56 AM9/14/09
to hadley wickham, Juliet Hannah, ggp...@googlegroups.com
Thanks Hadley and Juliet,

Juliet, you are right that the plots are correct when exported in pdf
form, and when I run the code using Linux (Ubuntu) everything also
looks fine. Darn that Bill Gates ;)

Wade
Reply all
Reply to author
Forward
0 new messages