[R] ggplot2: ordering categorial data

Christoph Krammer ck at altaica.de
Sun Oct 14 11:30:11 CEST 2007


Hello again,

everytime I think I got something to work, the next issue comes up...

I have the following data.frame, I want to visualize:

> data_rb
   tld  spam1     spam2 share
1   ca 826436     73452 0.0889
2  org 470550     25740 0.0547
3   de 156042     15531 0.0995
4  com 140753      7527 0.0535
5  edu  34845      2507 0.0719
6  net  12781       382 0.0299
7   ru   7648        18 0.0024
8   tw   2290         2 0.0009
9   uk   2283        22 0.0096
10  kr    971         7 0.0072

The perfect version of the final plot would look like this:
TLD is the X axis, ordered by the spam1 values
spam1 and spam2 are on the same Y axis, both as line plots
share is on a second Y axis, again as line plots
the three lines should appear in different colours

I first tried to do a bar plot with the following command:
qplot(tld, spam, data=data_rb, geom="bar", position="dodge") +
geom_bar(aes(y=data_rb$stockspam), position="dodge")

But this seems to stack spam1 and spam2 values.

When I try to do a lineplot, I get the following error message:
> qplot(tld, spam, data=data_rb, geom="line")
Error in unit(x0, default.units) : 'x' and 'units' must have length > 0

Can anyone help me with this?

Thanks and regards,
 Christoph



More information about the R-help mailing list