Kryo
Kryo

Reputation: 943

How to modify ggplot2 scatter plot

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?

Upvotes: 2

Views: 113

Answers (1)

Konrad
Konrad

Reputation: 18657

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.

Upvotes: 2

Related Questions