Adding a measure of precision to geom_point plot

45 views
Skip to first unread message

Manuel Spínola

unread,
Feb 26, 2011, 8:17:10 AM2/26/11
to ggplot2
Dear list members,

I am trying to add a measure of precision (specifically the standard error) to a bubble plot but in ggplot2 using geom_point.

The standard error is stored in the variable (column) ACE_EE

What I would like to get is a bubble with an extra layer representing the ee.

How is it possible?

Best,

Manuel

> dput(aves)
structure(list(x = c(554346, 545940, 552583, 571516, 572638,
541466, 584346, 605458, 557940, 545819, 564000, 569063, 558524,
580927, 568501, 556406, 561106, 544852, 543439, 547701, 557471,
564927, 563819, 543375, 544450, 555762, 569219, 557059, 562211,
541168, 558524, 576689, 571841, 567576, 584372.56, 563327, 575154,
537405, 591701, 593249, 566245, 584329, 576628, 583330), y = c(979674,
992481, 999404, 1003965, 1003838, 990078, 993674, 977900, 993008,
988568, 992000, 1005593, 993769, 1002327, 1010160, 1017254, 998903,
992231, 992188, 992961, 991135, 1008921, 1012081, 969577, 983881,
997597, 1012536, 1004354, 978257, 971405, 993769, 1004032, 1005402,
1005835, 993974.23, 1003084, 986929, 1046313, 1014019, 1010099,
1007254, 1000072, 1004458, 992719), sitio = structure(1:44, .Label = c("Ajuntaderas",
"Arrocera", "Balsar", "Bijagual 1", "Bijagual 2", "Boca Brava",
"Brujo", "Brusmalis", "Camaronal", "Camaronera", "Cañablancal",
"Caracol", "Casa de máquinas", "Cataratas", "Ceibo", "China Kichá",
"Colinas", "Cortez", "Cuadradal", "Delicias", "Desfogue", "Dibujada",
"El Tigre", "Estero seco", "Estero zacate", "Filadelfia", "Finca de caña-Remolino",
"Guagaral", "Hacienda", "Isla Violines", "Jalisco", "Margen  derecha",
"Ocochovi", "Paso La tinta", "Paso real", "Pilas", "Progreso",
"Río buena vista", "Río Cabagra", "Río Mosca", "Sabana", "San Andrés",
"SPMI", "Torta de huevo"), class = "factor"), ACE = c(24L, 50L,
6L, 104L, 93L, 15L, 49L, 13L, 48L, 31L, 21L, 131L, 171L, 91L,
87L, 75L, 113L, 19L, 28L, 40L, 81L, 75L, 128L, 17L, 20L, 123L,
96L, 33L, 28L, 8L, 172L, 33L, 121L, 88L, 28L, 147L, 90L, 13L,
29L, 6L, 80L, 76L, 81L, 10L), ACE_SE = c(1.99, 3.86, 1.17, 6.2,
5.72, 1.32, 3.37, 0.96, 3.57, 2.71, 2.39, 5.64, 7.61, 5.33, 4.87,
3.9, 5.57, 2.66, 0.97, 3.22, 4.04, 3.81, 6.53, 1.88, 2.08, 6.99,
4.93, 1.37, 2.6, 0.94, 7.56, 2.83, 5.88, 4.53, 2.46, 7.78, 5.85,
1.86, 3.64, 0, 6.86, 4.68, 5.24, 0.95)), .Names = c("x", "y",
"sitio", "ACE", "ACE_SE"), class = "data.frame", row.names = c(NA,
-44L))

--
Manuel Spínola, Ph.D.
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspi...@una.ac.cr
mspin...@gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río
Institutional website: ICOMVIS

Brandon Hurr

unread,
Feb 26, 2011, 9:09:21 AM2/26/11
to Manuel Spínola, ggplot2
I'm not sure if this works or not, but.... 

ggplot(data=aves, aes(x=x, y=y))+geom_point(aes(size=ACE), color="pink")+geom_text(aes(x=x+500, label=sitio), size=2, hjust=0)+geom_point(aes(size=ACE_SE))+theme_bw()

Brandon

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Manuel Spínola

unread,
Feb 26, 2011, 10:03:19 AM2/26/11
to Brandon Hurr, ggplot2
Thank you very much Brandon,

I think that is the way.
Is it possible to show the legend with the pink color instead of black?

Best,

Manuel

Brandon Hurr

unread,
Feb 26, 2011, 12:00:25 PM2/26/11
to Manuel Spínola, ggplot2
Manual, 

I've been trying, but I'm not sure it's working. 

I wondering if maybe it would be better to melt the dataframe and color with scale_colour_manual(). 

molten.aves<-melt(aves, id.vars=c("x", "y", "sitio"))

ggplot(data=molten.aves, aes(x=x, y=y))+geom_point(aes(colour=variable, size=value))+geom_text(aes(x=x+500, label=sitio), size=2, hjust=0, alpha=0.5)+theme_bw()+scale_colour_manual(values=c("pink", "black"))

Better? Worse?

Brandon

Manuel Spínola

unread,
Feb 26, 2011, 6:10:13 PM2/26/11
to Brandon Hurr, ggplot2
Thank you very much Brandon,

Is close to what I want but I want to control the scale of each each geom_point and the legends fro each geom_point.

Is that possible?

Best,

Manuel

Ista Zahn

unread,
Feb 26, 2011, 7:17:04 PM2/26/11
to Manuel Spínola, Brandon Hurr, ggplot2
Hi,
Sorry for butting in here -- I'd like to help but I'm unclear about
what exactly the goal is:

On Sat, Feb 26, 2011 at 11:10 PM, Manuel Spínola <mspin...@gmail.com> wrote:
> Thank you very much Brandon,
>

> Is close to what I want but I want to control the scale of each each
> geom_point and the legends fro each geom_point.

You _are_ controlling the scale of geom_point (through the
size=argument). Or do you mean something else by "scale"? Can you
clarify what exactly you want to do?

--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

Manuel Spínola

unread,
Feb 26, 2011, 8:13:04 PM2/26/11
to Ista Zahn, Brandon Hurr, ggplot2
Thank you very much Ista,

I am trying to plot 2 geom_point in the same plot, one for the number of species and the other for the standard error.
See attached plots.

I would like to have 2 legends one for the number of species and the other for the standard error.

Best,

Manuel
withSE.pdf
2legends.pdf

Ista Zahn

unread,
Feb 26, 2011, 10:26:57 PM2/26/11
to Manuel Spínola, Brandon Hurr, ggplot2
OK, I think I see now. I dont' think it can be done well. Esentially
you want to map two variables to the size aesthetic, which will always
be confusing. You can sort of fake it (Brandon showed a couple of
possibilities) but I think it's best to use another aesthetic. What
about


ggplot(data=aves, aes(x=x, y=y))+geom_point(aes(size=ACE,
color=ACE_SE))+geom_text(aes(x=x+500, label=sitio), size=2, hjust=0)

Best,
Ista


On Sun, Feb 27, 2011 at 1:13 AM, Manuel Spínola <mspin...@gmail.com> wrote:
> Thank you very much Ista,
>
> I am trying to plot 2 geom_point in the same plot, one for the number of
> species and the other for the standard error.
> See attached plots.
>
> I would like to have 2 legends one for the number of species and the other
> for the standard error.
>
> Best,
>
> Manuel
>
> On 26/02/2011 06:17 p.m., Ista Zahn wrote:
>

Manuel Spínola

unread,
Feb 27, 2011, 8:34:20 AM2/27/11
to Ista Zahn, Brandon Hurr, ggplot2
That works.

Thank you very much Ista.
Attached is the plot.

Best,

Manuel
conEE.pdf
Reply all
Reply to author
Forward
0 new messages