tags:

views:

69

answers:

3

I've got a scatter plot. I'd like to scale the size of each point by its frequency. So I've got a frequency column of the same length. However, if I do:

... + geom_point(size=Freq)

I get this error:

When _setting_ aesthetics, they may only take one value. Problems: size

which I interpret as all points can only have 1 size. So how would I do what I want?

Update: data is here The basic code I used is:

dcount=read.csv(file="New_data.csv",header=T)
ggplot(dcount,aes(x=Time,y=Counts)) + geom_point(aes(size=Freq))
+1  A: 

Have you tried..

+ geom_point(aes(size = Freq))

Aesthetics are mapped to variables in the data with the aes function. Check out http://had.co.nz/ggplot2/geom_point.html

gd047
Yes. still does not scale the points according to the frequency. It does create a gradient of point sizes that have nothing to do with the Freq value.
Maiasaura
As always a reproducible example is key
hadley
Sure, I've included a sample of the data and the code in my edited post.
Maiasaura
+1  A: 

If the code gd047 gave doesn't work, I'd double check that your Freq column is actually called Freq and that your workspace doesn't have some other object called Freq. Other than that, the code should work. How do you know that the scale has nothing to do with the frequency?

JoFrhwld
+1  A: 

ok, this might be what you're looking for. The code you provided above aggregates the information into four categories. If you don't want that, you can specify the categories with scale_size_manual().

sizes <- unique(dcount$Freq)
names(sizes) <- as.character(unique(dcount$Freq))

ggplot(dcount,aes(x=Time,y=Counts)) + geom_point(aes(size=as.factor(Freq))) + scale_size_manual(values = sizes/2)
apeescape
Thanks much, apeescape! That is exactly what I was looking for.cheers.
Maiasaura