Reputation: 32996
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))
Upvotes: 3
Views: 5216
Reputation: 1099
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)
Upvotes: 2
Reputation: 9047
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?
Upvotes: 1
Reputation: 30485
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
Upvotes: 3