How geom_point differ from geom_jitter in ggplot2 package?

r
ggplot2

#1

I am plotting a scatterplot using the ggplot2 package in R .I have created a layer for geom_point for the creation of scatter plot.

ggplot(aes(x=age,y=friend_count),data=pf)+xlim(13,90)+geom_point(alpha=1/20)

But while searching I found that we can add a layer of geom_jitter to make a similar plot.But I am unable to find the difference.


#2

@harry

jitters - add noise to the plot.It is useful when we want to convert the discrete plot to make continuous for better visualization.

You can easily that the age in the second plot becomes continuous.

Hope this helps!

Regards,
Hinduja


#3

Also adding to what @hinduja1234 mentioned, we can add jitters directly through the geom_point code

data1 <- data.frame(x=c(1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2),y=c(3,1,5,2,4,2,2,7,3,1,5,2,4,2,2,7))
# Normal geom_point PLOT
ggplot(aes(x=x,y=y),data=data1) + geom_point()
# geom_point PLOT with jitter
ggplot(aes(x=x,y=y),data=data1) + geom_point(position='jitter')
# geom_jitter plot ( This has the same effect as geom_point with jitter )
ggplot(aes(x=x,y=y),data=data1) + geom_jitter()

Anant