2

Here is my sample dataset:

df1 = data.frame(Count.amp = c(8,8,1,2,2,5,8), Count.amp.1 = c(4,4,2,3,2,5,4))

I tried

library(ggplot2)
qplot(Count.amp,Count.amp.1, data=df1)  

Is there any way to plot in such a way that the size of the dot is proportional to the number of elements in each dots?

1 Answer 1

2

Yes, broadly speaking you are looking at creating a bubble plot, this code:

df1 = data.frame(Count.amp = c(8,8,1,2,2,5,8), Count.amp.1 = c(4,4,2,3,2,5,4))
df1$sum <- df1$Count.amp + df1$Count.amp.1
ggplot(df1, aes(x=Count.amp, y=Count.amp.1, size=sum),guide=FALSE)+
  geom_point(colour="white", fill="red", shape=21)+ scale_size_area(max_size = 15)+
  theme_bw()

would give you something like that: bubble plot It wasn't immediately clear to me what do yo mean by the number of elements but on principle you can pass any figures into the size= to get the desired result.

Sign up to request clarification or add additional context in comments.

3 Comments

I was trying to convey that the size of the bubble present in the extreme right should be the largest because it contains more entries in the data.frame
@Kryo Try something like df1$nrep <- apply(df1, 1, function(r) sum(df1[,1] == r[1] & df1[,2] == r[2])) and then size=nrep.
@Kryo I got you now. If you are simply interested in counting occurrences in a variable you have multiple options, for instance you could use count(numbers) from the plyr package. Have a look at this discussion where possible approaches are discussed at lengths. Of course, the solution suggested by Molx should also work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.