Alpha sets the transparency for the scatter plot.
Open up R studio and type in the following code. 'diamonds' is a dataset that already exists in R.
ggplot(aes(x=diamonds$depth,y=diamonds$price),data=diamonds) +geom_point()

In the above plot there is plenty of overlapping of the datapoints, i.e the x and y co-ordinates are the same for a large number of points.
In order to have a better visualization we use the alpha function. Try running this code in R studio.
ggplot(aes(x=diamonds$depth,y=diamonds$price),data=diamonds) +geom_point(alpha=1/20)

Now, what we observe here is that alpha has grouped every 20 overlaps and shown it as a black dot. The lesser the overlaps the lighter the black dots are and as the overlaps getter higher the black dot become darker.
This way, we can quickly understand that the density of overlaps in the graph.
Open up R studio and type in the following code. 'diamonds' is a dataset that already exists in R.
ggplot(aes(x=diamonds$depth,y=diamonds$price),data=diamonds) +geom_point()

In the above plot there is plenty of overlapping of the datapoints, i.e the x and y co-ordinates are the same for a large number of points.
In order to have a better visualization we use the alpha function. Try running this code in R studio.
ggplot(aes(x=diamonds$depth,y=diamonds$price),data=diamonds) +geom_point(alpha=1/20)

Now, what we observe here is that alpha has grouped every 20 overlaps and shown it as a black dot. The lesser the overlaps the lighter the black dots are and as the overlaps getter higher the black dot become darker.
This way, we can quickly understand that the density of overlaps in the graph.
No comments:
Post a Comment