I'd like to know how to transform a scatter plot into a datum plot in the region, for example, where there are few dots, the region's color will be light, where there are many dots the color of the region will be darker. Thanks!
I'd like to know how to transform a scatter plot into a datum plot in the region, for example, where there are few dots, the region's color will be light, where there are many dots the color of the region will be darker. Thanks!
Using ggplot2
the following scatterplot:
library(ggplot2)
ggplot(faithful, aes(x = eruptions, y = waiting)) +
geom_point() +
xlim(0.5, 6) +
ylim(40, 110)
Thiscanbedonebychangingthelinegeom_point
:
ggplot(faithful,aes(x=eruptions,y=waiting))+stat_density_2d(aes(fill=..level..),geom="polygon") +
xlim(0.5, 6) +
ylim(40, 110)
Youcanalsodoitlikethis:
ggplot(faithful,aes(x=eruptions,y=waiting))+geom_bin2d()+xlim(0.5,6)+ylim(40,110)