set default shapes

27 views
Skip to first unread message

Matthieu Dubois

unread,
Jun 26, 2009, 11:09:53 AM6/26/09
to Ggplot2 Help
dear all

the question might potentially be basic. Apologises if it is the case. I'm currently able to set manually shapes for a given plot (using scale_shape_manual(values=c(1,16)) ). Is there a way to define those values as default ? 

Regards, 

Matthieu

Matthieu Dubois
Post-doctoral fellow

Psychology and NeuroCognition Lab (CNRS UMR 5105)
Université Pierre Mendès-France
BP47 --- 38040 Grenoble Cedex 9 --- France





baptiste auguie

unread,
Jun 26, 2009, 12:23:29 PM6/26/09
to Matthieu Dubois, ggplot2
Hi,

I was going to suggest ?set_default_scale but I can't get it to work
for shapes.

set_default_scale("shape","manual", "shape",value=c(1,16))
> qplot(x,y,data=data.frame(x=1,y=1,s="a"),shape=s) + scale_shape_manual()
Error in names(output_df) <- output :
'names' attribute [1] must be the same length as the vector [0]

You might have better luck than me.

baptiste
--
_____________________________

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

http://newton.ex.ac.uk/research/emag
______________________________

Matthieu Dubois

unread,
Jun 26, 2009, 1:31:33 PM6/26/09
to baptiste auguie, Ggplot2 Help
Hi,

I indeed also tried using set_default_shape(), but was unlucky...

hadley wickham

unread,
Jul 2, 2009, 10:03:56 AM7/2/09
to baptiste auguie, Matthieu Dubois, ggplot2
On Fri, Jun 26, 2009 at 11:23 AM, baptiste
auguie<bapt...@googlemail.com> wrote:
>
> Hi,
>
> I was going to suggest ?set_default_scale but I can't get it to work
> for shapes.
>
> set_default_scale("shape","manual", "shape",value=c(1,16))
>> qplot(x,y,data=data.frame(x=1,y=1,s="a"),shape=s) + scale_shape_manual()
> Error in names(output_df) <- output :
>  'names' attribute [1] must be the same length as the vector [0]

It works for me.

set_default_scale("shape","manual", "shape",value=c(1,16))
qplot(x,y,data=data.frame(x=1,y=1,s="a"),shape=s)

You don't need the extra + scale_shape_manual(). If I've missed
something, please create a reproducible example that makes it really
really really obvious what the problem is.

Hadley


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

baptiste auguie

unread,
Jul 2, 2009, 10:28:17 AM7/2/09
to hadley wickham, ggplot2
> It works for me.
>
> set_default_scale("shape","manual", "shape",value=c(1,16))
> qplot(x,y,data=data.frame(x=1,y=1,s="a"),shape=s)
>
> You don't need the extra  + scale_shape_manual().  If I've missed
> something, please create a reproducible example that makes it really
> really really obvious what the problem is.
>

I guess the problem is that,

set_default_scale("shape","manual", "shape",value=c(2))
qplot(x,y,data=data.frame(x=1,y=1,s="a"),shape=s)

produces the same output (on my machine anyway) as,

set_default_scale("shape","manual", "shape",value=c(1))
qplot(x,y,data=data.frame(x=1,y=1,s="a"), shape=s)

(both produce a black disc = 16 in the center, where one'd expect an
open triangle for the first case and an open circle for the second)

i.e., the default shapes used by the scale aren't affected. Or did I
miss the intended effect of
set_default_scale ?

When i played with this last time, I was hoping to do something along
those lines,

d = data.frame(x=1:10,y=1:10,s=rep(letters[1:3],length=10))

qplot(x,y,data=d,shape=s)

ScaleShape$output_set <- function (.)
{

c(1, 16, 17, 15, 3, 7, 8)[1:length(.$input_set())]

}

qplot(x,y,data=d,shape=s)

However this is rather destructive (the only way to revert back seems
to be a restart of R?!). I haven't been able to make a copy of the
scale that doesn't affect the ggplot2 version (probably something to
do with the proto system).

sessionInfo()
R version 2.9.0 (2009-04-17)
i386-apple-darwin9.6.0

locale:
en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

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

other attached packages:
[1] ggplot2_0.8.2 reshape_0.8.2 plyr_0.1.5 proto_0.3-8


Does this make sense?

baptiste


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

hadley wickham

unread,
Jul 3, 2009, 1:52:33 PM7/3/09
to baptiste auguie, ggplot2
On Thu, Jul 2, 2009 at 9:28 AM, baptiste auguie<bapt...@googlemail.com> wrote:
>> It works for me.
>>
>> set_default_scale("shape","manual", "shape",value=c(1,16))
>> qplot(x,y,data=data.frame(x=1,y=1,s="a"),shape=s)
>>
>> You don't need the extra  + scale_shape_manual().  If I've missed
>> something, please create a reproducible example that makes it really
>> really really obvious what the problem is.
>>
>
> I guess the problem is that,
>
> set_default_scale("shape","manual", "shape",value=c(2))
> qplot(x,y,data=data.frame(x=1,y=1,s="a"),shape=s)
>
> produces the same output (on my machine anyway) as,
>
> set_default_scale("shape","manual", "shape",value=c(1))
> qplot(x,y,data=data.frame(x=1,y=1,s="a"), shape=s)

Ok, there are two problems:

* firstly you want to be setting the default scale for discrete
shapes - not "manual" shapes

* however, set_default_scale("shape","discrete", "manual",value=c(1))
doesn't work for reasons I can't immediately remember.

I'll look into it.

Hadley

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

Reply all
Reply to author
Forward
0 new messages