Represent point size according to frequency

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Represent point size according to frequency

swertie
Hello! I would like to make a scatterplot of my data, but the problem is that several points have the same x and y values and are represented as only one point.  I wonder if there is a way to represent the data points, but with point size representing the frequency of the depicted x-y value?
Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: Represent point size according to frequency

Michael Weylandt
I think it's more generally encouraged to "jitter" the points in this
circumstance.

RMW

On Mon, Oct 22, 2012 at 9:34 AM, swertie <[hidden email]> wrote:

> Hello! I would like to make a scatterplot of my data, but the problem is that
> several points have the same x and y values and are represented as only one
> point.  I wonder if there is a way to represent the data points, but with
> point size representing the frequency of the depicted x-y value?
> Thank you!
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Represent-point-size-according-to-frequency-tp4646976.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Represent point size according to frequency

Jose Iparraguirre
In reply to this post by swertie
Shortly ago I did something similar to what you intend to.

The data frame was called 'fore'. There were eight different variables and I wanted to plot each one by column, and depict the frequencies in terms of the size of the dots. The problem I ran into is that the plots got extremely big for some particular cases with high frequencies -fortunately, in my case, it didn't matter whether I had a value of 4 or more: I could depict them all with the same size. Hence, I plotted frequency values 1, 2, 3, and 4.

There may be more elegant ways, but this was my rough and ready attempt:

> op <- par(mar=c(3,4,1,1))
> plot(c(1:8),col="white",
+ ylim=c(min(na.omit(fore)),max(na.omit(fore))),xaxt="n", xlab="",ylab="%")
> grid()

> for (i in 1:ncol(fore)){
+ cex.dots=ifelse(as.numeric(table(fore[,i]))>4,4,as.numeric(table(fore[,i])))
+ points(x=rep(i,length(na.omit(fore[,i]))),
+ y=na.omit(fore[,i]),pch=19, cex=cex.dots)
+ }

> title, etc...
> par(op)


Forgive me for the shameless plugging, but you can see the final result on page 44, Figure 39, of Age UK's Chief Economist's Report (http://www.ageuk.org.uk/Documents/EN-GB/For-professionals/Research/Age%20UK%20Chief%20Economist%20Report%20Autumn%202012.pdf)

Hope this helps!

José


José Iparraguirre
Chief Economist
Age UK

T 020 303 31482
E [hidden email]
Twitter @jose.iparraguirre@ageuk


Tavis House, 1- 6 Tavistock Square
London, WC1H 9NB
www.ageuk.org.uk | ageukblog.org.uk | @ageukcampaigns


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of swertie
Sent: 22 October 2012 09:35
To: [hidden email]
Subject: [R] Represent point size according to frequency

Hello! I would like to make a scatterplot of my data, but the problem is that
several points have the same x and y values and are represented as only one
point.  I wonder if there is a way to represent the data points, but with
point size representing the frequency of the depicted x-y value?
Thank you!



--
View this message in context: http://r.789695.n4.nabble.com/Represent-point-size-according-to-frequency-tp4646976.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email] 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.

Age UK and YouthNet are official charities for the Virgin London Marathon 2013

We need you to Run for it. Join the team and help raise vital funds to bring generations together to combat loneliness and isolation.

Go to http://www.runforit.org.uk for more information or contact Helen Parson at [hidden email] or on 020 303 31369.

Age UK and YouthNet. A lifeline, online.

www.runforit.org.uk



Age UK Improving later life

www.ageuk.org.uk



-------------------------------
Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798).
Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.

For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer
Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health
cash plans customers respectively.  Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and
regulated by the Financial Services Authority.
------------------------------

This email and any files transmitted with it are confide...{{dropped:28}}

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Represent point size according to frequency

swertie
Thank you very much. I managed to do it with a similar approach and it looks like what I expected.
Reply | Threaded
Open this post in threaded view
|

Re: Represent point size according to frequency

swertie
In reply to this post by Michael Weylandt
Thank you for your comment. I would be very interested, but I did not know about jitter. Would you have a small example?
Reply | Threaded
Open this post in threaded view
|

Re: Represent point size according to frequency

Michael Weylandt
example(jitter)
library('ggplot2')
example(geom_jitter)

RMW

On Monday, October 22, 2012, swertie wrote:

> Thank you for your comment. I would be very interested, but I did not know
> about jitter. Would you have a small example?
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Represent-point-size-according-to-frequency-tp4646976p4647023.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] <javascript:;> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Represent point size according to frequency

swertie
thank you, that looks good
Reply | Threaded
Open this post in threaded view
|

Represent point size according to frequency

Henrik Pärn
In reply to this post by swertie
You may also have a look here:

http://flowingdata.com/2010/11/23/how-to-make-bubble-charts/

Note the "Circles incorrectly sized by radius instead of area. Large values appear much bigger."

Similar point made here:
https://stat.ethz.ch/pipermail/r-help/2011-January/265475.html



Message: 44
Date: Mon, 22 Oct 2012 08:05:24 -0700 (PDT)
From: swertie <[hidden email]>
To: [hidden email]
Subject: Re: [R] Represent point size according to frequency
Message-ID: <[hidden email]>
Content-Type: text/plain; charset=us-ascii

Thank you very much. I managed to do it with a similar approach and it looks
like what I expected.

--
Henrik Pärn
Centre for Conservation Biology
Department of Biology
Norwegian University of Science and Technology
NO-7491 Trondheim
NORWAY

Office: +47 735 96084
Mobile: +47 909 89 255
Fax: +47 735 96100

        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.