Hi:
The major step is to convert the frequencies to proportions and then
use the labels = percent option in scale_y_continuous() (after loading
the scales package) to label the y-axis in terms of percentages. After
making a facsimile data frame out of your posted graph, I did the
following.
My fake data frame m has the following characteristics: (frequencies
are rounded and estimated)
> str(m)
'data.frame': 84 obs. of 4 variables:
$ type: num 1 1 1 1 1 1 1 1 1 1 ...
$ day : int 0 0 0 0 0 0 1 1 1 1 ...
$ pct : num 40 50 60 70 80 90 40 50 60 70 ...
$ freq: num 5450 4950 4100 3600 3150 2900 800 1250 1300 1900 ...
> head(m)
type day pct freq
1 1 0 40 5450
2 1 0 50 4950
3 1 0 60 4100
4 1 0 70 3600
5 1 0 80 3150
6 1 0 90 2900
# Convert pct to factor for the legend to be drawn as in your graph:
m$pct <- factor(m$pct)
# Uncomment to load the following packages:
# library('ggplot2')
# library('scales')
# library('plyr')
# Use plyr::ddply to generate overall proportions by type (don't know
if this is correct,
# but the end result looks like your original if I do it this way)
# The mutate() function in plyr adds variables to an existing data frame,
# similar to transform() in base R:
m2 <- ddply(m, .(type), mutate, prop = round(freq/sum(freq), 4))
# Now plot (notice the scale_y_continuous() option):
ggplot(m2, aes(x = day, y = prop, colour = pct) +
geom_line(aes(group = pct), size = 1) +
scale_y_continuous(labels = percent) +
facet_wrap(~ type, nrow = 1)
You should be able to get a data frame conversion of the frequencies
in your data as follows:
dfrq <- as.data.frame(with(dat, table(type, day, pct)))
This should look something like the fake data frame m I created above.
I don't know which types of proportions you want, but the idea in the
call that leads to my object m2 works pretty well. The terms within
.() in ddply() are the factors over which the proportions would be
calculated.
HTH,
Dennis
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example:
https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2