I have a simple problem that I just cannot get - I need to create a
simple pie chart. My data frame is
data <- data.frame(cluster = paste("Cluster", 1:4), size =
c(0.5519, 0.2238, 0.1544, 0.0698))
where "size" is the proportion of consumers in each cluster (and sum to
1.0). The pie should have four slices, each the size of "size" and the
legend should simply be the cluster names from "cluster". How do I do
this????
Also, how do I get labels on the slices (e.g., "Cluster 1: 0.5519")?
Thanks,
Walt
________________________
Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ 08536
________________________
(V) 609-936-8999
(F) 609-936-3733
wa...@dataanalyticscorp.com
www.dataanalyticscorp.com
_____________________________________________________
--
________________________
Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ 08536
________________________
(V) 609-936-8999
(F) 609-936-3733
wa...@dataanalyticscorp.com
www.dataanalyticscorp.com
--
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
This helped. I was missing the "weight = size". Now for labels on the
slices.
Thanks,
Walt
________________________
Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ 08536
________________________
(V) 609-936-8999
(F) 609-936-3733
wa...@dataanalyticscorp.com
www.dataanalyticscorp.com
_____________________________________________________
>> wa...@dataanalyticscorp.com <mailto:wa...@dataanalyticscorp.com>
>>>> To unsubscribe: email ggplot2+u...@googlegroups.com<ggplot2%2Bunsu...@googlegroups.com>
>>>> More options: http://groups.google.com/group/ggplot2
>>>>
>>>
>>> --
>>> 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<ggplot2%2Bunsu...@googlegroups.com>
>>> More options: http://groups.google.com/group/ggplot2
>>>
>>
>>
>> --
>> ________________________
>>
>> Walter R. Paczkowski, Ph.D.
>> Data Analytics Corp.
>> 44 Hamilton Lane
>> Plainsboro, NJ 08536
>> ________________________
>> (V) 609-936-8999
>> (F) 609-936-3733
>> wa...@dataanalyticscorp.com
>> www.dataanalyticscorp.com
>>
>> --
>> 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<ggplot2%2Bunsu...@googlegroups.com>
I also played around with geom_text but then gave up since it became too
much work for a simple problem. Pie charts are used all the time in
business, so it would seem to me that being able to create them in
ggplot2 would be a easy. But not so. From a business perspective, this
limits ggplot2. Incidentally, the pie chart has an annoying ring around
it showing the degrees of the circle. This is a nuisance that would be
very difficult to explain to a client. Another limitation.
Thanks,
Walt
________________________
Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ 08536
________________________
(V) 609-936-8999
(F) 609-936-3733
wa...@dataanalyticscorp.com
www.dataanalyticscorp.com
_____________________________________________________
> wa...@dataanalyticscorp.com <mailto:wa...@dataanalyticscorp.com>
> www.dataanalyticscorp.com <http://www.dataanalyticscorp.com>
> <mailto:wa...@dataanalyticscorp.com
> <mailto:wa...@dataanalyticscorp.com>>
>
> www.dataanalyticscorp.com <http://www.dataanalyticscorp.com>
>
> _____________________________________________________
>
>
> --
> ________________________
>
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> ________________________
> (V) 609-936-8999
> (F) 609-936-3733
> wa...@dataanalyticscorp.com <mailto:wa...@dataanalyticscorp.com>
> www.dataanalyticscorp.com <http://www.dataanalyticscorp.com>
>
> --
> 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
> <mailto:ggp...@googlegroups.com>
> To unsubscribe: email ggplot2+u...@googlegroups.com
> <mailto:ggplot2%2Bunsu...@googlegroups.com>
> More options: http://groups.google.com/group/ggplot2
>
>
> --
> 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
> <mailto:ggp...@googlegroups.com>
> To unsubscribe: email ggplot2+u...@googlegroups.com
> <mailto:ggplot2%2Bunsu...@googlegroups.com>
> More options: http://groups.google.com/group/ggplot2
>
>
>
> --
> ________________________
>
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> ________________________
> (V) 609-936-8999
> (F) 609-936-3733
> wa...@dataanalyticscorp.com <mailto:wa...@dataanalyticscorp.com>
> www.dataanalyticscorp.com <http://www.dataanalyticscorp.com>
>
> --
> 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
> <mailto:ggp...@googlegroups.com>
> To unsubscribe: email ggplot2+u...@googlegroups.com
> <mailto:ggplot2%2Bunsu...@googlegroups.com>
I see how position is calculated, that could be generalized. Perhaps to a geom_pie
How do you calculate position2, is that trial and error for placing the labels?
>>>>>>>> <ggplot2%2Bunsu...@googlegroups.com<ggplot2%252Buns...@googlegroups.com>
>>>>>>>>>
>>>>>>>> More options: http://groups.google.com/group/ggplot2
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>> --
>>>>>>> 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<ggplot2%2Bunsu...@googlegroups.com>
>>>>>>> <ggplot2%2Bunsu...@googlegroups.com<ggplot2%252Buns...@googlegroups.com>
>>>>>>>>
>>>>>>> More options: http://groups.google.com/group/ggplot2
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> --
>>>>>> ________________________
>>>>>>
>>>>>> Walter R. Paczkowski, Ph.D.
>>>>>> Data Analytics Corp.
>>>>>> 44 Hamilton Lane
>>>>>> Plainsboro, NJ 08536
>>>>>> ________________________
>>>>>> (V) 609-936-8999
>>>>>> (F) 609-936-3733
>>>>>> wa...@dataanalyticscorp.com
>>>>>> www.dataanalyticscorp.com
>>>>>>
>>>>>> --
>>>>>> 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<ggplot2%2Bunsu...@googlegroups.com>
>>>>>> <ggplot2%2Bunsu...@googlegroups.com<ggplot2%252Buns...@googlegroups.com>
> <awesome.pie.png>
Walt
> <wa...@dataanalyticscorp.com <mailto:wa...@dataanalyticscorp.com>>
> <mailto:wa...@dataanalyticscorp.com>> wrote:
>
>
> Hi,
>
> This helped. I was missing the "weight = size".
> Now for labels on the
> slices.
>
>
> Thanks,
>
> Walt
>
> ________________________
>
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> ________________________
> (V) 609-936-8999
> (F) 609-936-3733
> wa...@dataanalyticscorp.com
> <mailto:wa...@dataanalyticscorp.com>
> www.dataanalyticscorp.com
> <http://www.dataanalyticscorp.com>
>
> <mailto:wa...@dataanalyticscorp.com><mailto:wa...@dataanalyticscorp.com
> <mailto:wa...@dataanalyticscorp.com>>
>
> www.dataanalyticscorp.com
> <http://www.dataanalyticscorp.com>
>
> _____________________________________________________
>
>
> --
> ________________________
>
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> ________________________
> (V) 609-936-8999
> (F) 609-936-3733
> wa...@dataanalyticscorp.com
> <mailto:wa...@dataanalyticscorp.com>
> www.dataanalyticscorp.com
> <http://www.dataanalyticscorp.com>
>
> --
> 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
> <mailto:ggp...@googlegroups.com>
> To unsubscribe: email
> ggplot2+u...@googlegroups.com
> <mailto:ggplot2%2Bunsu...@googlegroups.com><ggplot2%2Bunsu...@googlegroups.com
> <mailto:ggplot2%252Buns...@googlegroups.com>>
> More options:
> http://groups.google.com/group/ggplot2
>
>
> --
> 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
> <mailto:ggp...@googlegroups.com>
> To unsubscribe: email
> ggplot2+u...@googlegroups.com
> <mailto:ggplot2%2Bunsu...@googlegroups.com><ggplot2%2Bunsu...@googlegroups.com
> <mailto:ggplot2%252Buns...@googlegroups.com>>
> More options:
> http://groups.google.com/group/ggplot2
>
>
>
> --
> ________________________
>
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> ________________________
> (V) 609-936-8999
> (F) 609-936-3733
> wa...@dataanalyticscorp.com
> <mailto:wa...@dataanalyticscorp.com>
> www.dataanalyticscorp.com
> <http://www.dataanalyticscorp.com>
>
> --
> 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
> <mailto:ggp...@googlegroups.com>
> To unsubscribe: email
> ggplot2+u...@googlegroups.com
> <mailto:ggplot2%2Bunsu...@googlegroups.com><ggplot2%2Bunsu...@googlegroups.com
> <mailto:ggplot2%252Buns...@googlegroups.com>>
> More options: http://groups.google.com/group/ggplot2
>
>
> --
> 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
> <mailto:ggp...@googlegroups.com>
> To unsubscribe: email
> ggplot2+u...@googlegroups.com
> <mailto:ggplot2%2Bunsu...@googlegroups.com>
> More options: http://groups.google.com/group/ggplot2
>
>
>
>
> --
> ________________________
>
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> ________________________
> (V) 609-936-8999
> (F) 609-936-3733
> wa...@dataanalyticscorp.com <mailto:wa...@dataanalyticscorp.com>
> www.dataanalyticscorp.com <http://www.dataanalyticscorp.com>
>
> --
> 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
> <mailto:ggp...@googlegroups.com>
> To unsubscribe: email ggplot2+u...@googlegroups.com
> <mailto:ggplot2%2Bunsu...@googlegroups.com>
# I renamed your data object because data is also a function name
dat <- data.frame(cluster = paste("Cluster", 1:4), size = c(0.5519,
0.2238, 0.1544, 0.0698))
# pie chart with labels
# (side puzzle, which one of these colours is out of place?)
with(dat, pie(x = size, labels = paste(cluster, size, sep = ": "),
col = c("tomato3", "honeydew3", "papayawhip", "mintcream")))
# 4, 'mintcream'. Tomatoes, honeydew melons, and papayas are all
fruits, mintcream is not.
Cheers,
Josh
On Thu, Sep 30, 2010 at 9:16 AM, Data Analytics Corp.
<wa...@dataanalyticscorp.com> wrote:
> If I have to use SigmaPlot, Excel or Inkscape, then what's the purpose of
> ggplot2????
Consider these plots:
x <-c(.22, .25, .28, .25)
pie(x)
plot(x=1:4, y = x, ylim = c(0, .4))
x2 <- sample(x, 8, replace = TRUE)
pie(x2)
plot(x = 1:8, y = x2, ylim = c(0, .4))
These are not beautiful examples, but at least for me, it is much
slower and harder to read the pie chart than the scatter plot.
ggplot2 will easily do the scatter plot (and make it look much nicer
than the crass thing I presented here).
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/
Something like this...
xy<-data.frame(x=c(60, 25, 15), y=c(0,0,0))
t<-length(xy[[1]]
xy$y<-1/2*xy$x
for (i in 2:length(xy[[1]])){
xy$y[i]<-xy$y[i]+xy$x[i-1]
}
I know that's probably a horrible example, but it is 'an' example.
Although, Josh has a good point.
Brandon
Walt
For what it's worth, there's a small counter-literature (the Spence
2005 reference <http://www.psych.utoronto.ca/users/spence/Spence%202005.pdf>
from the wikipedia 'pie chart' article is a starting point) that says
pie charts aren't that bad
(although Few <http://www.perceptualedge.com/articles/08-21-07.pdf>, who
tries to be pretty thorough,
finds only one small case where they're provably better).
There's something to be said for culture, too. I think the example
above from population genetics isn't
that bad -- I don't think you'd gain that much by re-doing them as bar
charts or stacked bars.
data <- data.frame(cluster = paste("Cluster", 1:4), size = c(0.5519,
0.2238, 0.1544, 0.0698))
data$p<-(p<-cumsum(data$size)-diff(c(0,cumsum(data$size)))*(1-0.5)) #
is this simplest?
ggplot(data, aes(x = factor(1), fill = cluster, weight=size)) +
geom_bar(width=1) + geom_text(aes(x= 1.6, y=p,
angle=-p*360,label=size),vjust=0)+coord_polar(theta="y")
- you can control the distance between pie and text by changing x=1.6
- you can control the position of the text along the pie by changing 1-0.5
- you can also control the angle of the text.
On Fri, Oct 1, 2010 at 2:10 AM, Data Analytics Corp.
Data Analytics Corp. wrote:
> Yes, I could have used the function in base, but then why have ggplot2?
Because choice, in general, is good.
Several tools leads to best chance that what I want can be handled by
one of them.
I've found ggplot2 the best tool for my graphics needs, but I've never
used it to make a pie chart.
--Erik