I am creating a scatterplot with the following code.
pl<-ggplot(df,aes(x=Importance,y=Performance,fill=PBF,size=gapsize))+
geom_point(shape=21,colour="black")+scale_size_area(max_size=pointsizefactor)
points are plotted where the size of the point is related to a metric variable
gapsize and the fill color on the point is related to the variable PBF which is
a 4 level factor. This works exactly as I want with the points varying in size
based on the metric and being color coded. I get 2 legends on the side of the
plot, one related to the size of the dot and the other showing the color coding.
The problem is that the dots on the color coding legend are so small that it is
impossible to discern what color they are. The dots in the plot are large, so it
is clear what colors they are, but the legend is useless. How can I increase
the size of the points in the color legend.
pointsizefactor<-5
df
Importance Performance gapsize labels PBF
q50451 0.7079463 -0.7213622 2 a W
q50452 0.4489164 -0.5552116 1 b G
q50453 0.7714138 -0.6940144 5 c F
q50454 0.6284830 -0.6011352 3 d S
q50455 0.7131063 -0.6800826 4 e G
q50456 0.7038184 -0.6026832 6 f S
q50457 0.5201238 -0.3539732 8 g G
q50458 0.9195046 -0.8214654 2 h F
q50459 0.3797730 -0.4184727 1 i W
q504510 0.8065015 -0.6305470 7 j G
q504511 0.6062951 -0.4442724 6 k S
q504512 0.6253870 -0.4478844 8 l G
q504513 0.3813209 -0.4102167 2 m W
q504514 0.3813209 -0.3436533 3 n F
q504515 0.5185759 -0.4365325 5 o G
q504516 0.5872033 -0.4556244 6 p S
q504518 0.5397317 -1.0000000 1 q S
q504519 0.5882353 -0.4674923 9 r S
q504520 0.4205366 -0.4164087 4 s W
q504521 0.7616099 -0.3323013 10 t F
q504522 0.7213622 -0.6088751 7 u G
q504523 0.6780186 -0.6130031 8 v G
q504524 0.6904025 -0.3937049 10 w W
q504525 0.4143447 -0.4669763 4 x W
q504526 0.5779154 -0.2982456 9 y F
q504527 0.6718266 -0.3457172 10 z G
Thanks all
//Mike
W. Michael Conklin
Executive Vice President | Marketing Science
GfK Custom Research, LLC | 8401 Golden Valley Road | Minneapolis, MN, 55427
T +1 763 417 4545 | M +1 612 567 8287
www.gfk.com<http://www.gfk.com/>
[[alternative HTML version deleted]]
You can override the legend aesthetics, e.g.,
ggplot(df,aes(x=Importance,y=Performance,fill=PBF,size=gapsize))+
geom_point(shape=21,colour="black")+
scale_size_area(max_size=pointsizefactor) +
scale_fill_discrete(guide = guide_legend(override.aes = list(size = 4)))
Best,
Ista
On Thu, Oct 31, 2013 at 4:08 PM, Conklin, Mike (GfK)
<Mike.Conklin at gfk.com> wrote:> I am creating a scatterplot with the following code.
>
> pl<-ggplot(df,aes(x=Importance,y=Performance,fill=PBF,size=gapsize))+
>
geom_point(shape=21,colour="black")+scale_size_area(max_size=pointsizefactor)
>
> points are plotted where the size of the point is related to a metric
variable gapsize and the fill color on the point is related to the variable PBF
which is a 4 level factor. This works exactly as I want with the points varying
in size based on the metric and being color coded. I get 2 legends on the side
of the plot, one related to the size of the dot and the other showing the color
coding. The problem is that the dots on the color coding legend are so small
that it is impossible to discern what color they are. The dots in the plot are
large, so it is clear what colors they are, but the legend is useless. How can
I increase the size of the points in the color legend.
>
> pointsizefactor<-5
>
> df
>
> Importance Performance gapsize labels PBF
> q50451 0.7079463 -0.7213622 2 a W
> q50452 0.4489164 -0.5552116 1 b G
> q50453 0.7714138 -0.6940144 5 c F
> q50454 0.6284830 -0.6011352 3 d S
> q50455 0.7131063 -0.6800826 4 e G
> q50456 0.7038184 -0.6026832 6 f S
> q50457 0.5201238 -0.3539732 8 g G
> q50458 0.9195046 -0.8214654 2 h F
> q50459 0.3797730 -0.4184727 1 i W
> q504510 0.8065015 -0.6305470 7 j G
> q504511 0.6062951 -0.4442724 6 k S
> q504512 0.6253870 -0.4478844 8 l G
> q504513 0.3813209 -0.4102167 2 m W
> q504514 0.3813209 -0.3436533 3 n F
> q504515 0.5185759 -0.4365325 5 o G
> q504516 0.5872033 -0.4556244 6 p S
> q504518 0.5397317 -1.0000000 1 q S
> q504519 0.5882353 -0.4674923 9 r S
> q504520 0.4205366 -0.4164087 4 s W
> q504521 0.7616099 -0.3323013 10 t F
> q504522 0.7213622 -0.6088751 7 u G
> q504523 0.6780186 -0.6130031 8 v G
> q504524 0.6904025 -0.3937049 10 w W
> q504525 0.4143447 -0.4669763 4 x W
> q504526 0.5779154 -0.2982456 9 y F
> q504527 0.6718266 -0.3457172 10 z G
>
>
> Thanks all
>
> //Mike
>
> W. Michael Conklin
> Executive Vice President | Marketing Science
> GfK Custom Research, LLC | 8401 Golden Valley Road | Minneapolis, MN, 55427
> T +1 763 417 4545 | M +1 612 567 8287
> www.gfk.com<http://www.gfk.com/>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
As a starting point perhaps have a look at legend.key.size (unit)
in ?theme. It may do something like what you want with some tweaking. My quick
and dirty example just applies the command to both legends.
pl<-ggplot(dat1,aes(x=Importance,y=Performance,fill=PBF,size=gapsize))+
geom_point(shape=21,colour="black")
pl + theme(legend.key.size = unit(2, "cm"))
John Kane
Kingston ON Canada
> -----Original Message-----
> From: mike.conklin at gfk.com
> Sent: Thu, 31 Oct 2013 21:08:02 +0100
> To: r-help at r-project.org
> Subject: [R] help with ggplot legend specification
>
> I am creating a scatterplot with the following code.
>
> pl<-ggplot(df,aes(x=Importance,y=Performance,fill=PBF,size=gapsize))+
>
>
geom_point(shape=21,colour="black")+scale_size_area(max_size=pointsizefactor)
>
> points are plotted where the size of the point is related to a metric
> variable gapsize and the fill color on the point is related to the
> variable PBF which is a 4 level factor. This works exactly as I want
> with the points varying in size based on the metric and being color
> coded. I get 2 legends on the side of the plot, one related to the size
> of the dot and the other showing the color coding. The problem is that
> the dots on the color coding legend are so small that it is impossible to
> discern what color they are. The dots in the plot are large, so it is
> clear what colors they are, but the legend is useless. How can I
> increase the size of the points in the color legend.
>
> pointsizefactor<-5
>
> df
>
> Importance Performance gapsize labels PBF
> q50451 0.7079463 -0.7213622 2 a W
> q50452 0.4489164 -0.5552116 1 b G
> q50453 0.7714138 -0.6940144 5 c F
> q50454 0.6284830 -0.6011352 3 d S
> q50455 0.7131063 -0.6800826 4 e G
> q50456 0.7038184 -0.6026832 6 f S
> q50457 0.5201238 -0.3539732 8 g G
> q50458 0.9195046 -0.8214654 2 h F
> q50459 0.3797730 -0.4184727 1 i W
> q504510 0.8065015 -0.6305470 7 j G
> q504511 0.6062951 -0.4442724 6 k S
> q504512 0.6253870 -0.4478844 8 l G
> q504513 0.3813209 -0.4102167 2 m W
> q504514 0.3813209 -0.3436533 3 n F
> q504515 0.5185759 -0.4365325 5 o G
> q504516 0.5872033 -0.4556244 6 p S
> q504518 0.5397317 -1.0000000 1 q S
> q504519 0.5882353 -0.4674923 9 r S
> q504520 0.4205366 -0.4164087 4 s W
> q504521 0.7616099 -0.3323013 10 t F
> q504522 0.7213622 -0.6088751 7 u G
> q504523 0.6780186 -0.6130031 8 v G
> q504524 0.6904025 -0.3937049 10 w W
> q504525 0.4143447 -0.4669763 4 x W
> q504526 0.5779154 -0.2982456 9 y F
> q504527 0.6718266 -0.3457172 10 z G
>
>
> Thanks all
>
> //Mike
>
> W. Michael Conklin
> Executive Vice President | Marketing Science
> GfK Custom Research, LLC | 8401 Golden Valley Road | Minneapolis, MN,
> 55427
> T +1 763 417 4545 | M +1 612 567 8287
> www.gfk.com<http://www.gfk.com/>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your
desktop!