Reputation: 105
I am making a ggplot
for a data which shows two parameters Alcohol Consumption level
vs Annual Income of Family
.
There are many data points in a specific region of the graph, so I want to increase the size of these points compared to other regions where there are fewer data points. I don't know what to enter in the aes
parameter in geom_point
for this.
g <- ggplot(data = matpor, mapping = aes(AIncome, AConsumption))
g <- g + geom_point(data = matpor, aes())
g
Upvotes: 2
Views: 540
Reputation: 2797
Why increase the size of the point? You can increase the transparency of the points, or jitter?
For example, using the classical ggplot2::diamonds
example,
d <- ggplot(diamonds, aes(carat, price))
d + geom_point(alpha = 1/10)
scales the color to 1/10th of its original darkness.
Alternatively, to do what you want, you can use the stat_sum
statistic in the geom_count
geom to scale the size of the point based on how many data points are around it.
d + geom_count()
You will notice that with many, many data points in this data set, the size of the points will actually be obscured.
In many cases it is better to scale this value to a color, using e.g., a heatmap or 2d bin histogram.
d + geom_bin2d()
Upvotes: 3