library(ggplot2)
library(gcookbook)
str(heightweight) #查看数据集结构head(heightweight) #显示前6行
#-----------------------------------------1 基本散点图--------------------------------------------
ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point()
#-----------------------------------------2 基于类别型变量分组------------------------------------
ggplot(heightweight, aes(x=ageYear, y=heightIn, shape=sex, color=sex)) + geom_point()
#------------------------------------------3 基于连续型变量映射-------------------------------------
ggplot(heightweight, aes(x=ageYear, y=heightIn, size=weightLb, color=weightLb)) + geom_point()
#scale_size_area(),散点的面积正比于连续型变量的大小
ggplot(heightweight, aes(x=ageYear, y=heightIn, size=weightLb, color=sex)) + geom_point(alpha=.5)+ scale_size_area()
#使用大小与分布密度成正比例的点,不添加等高线
ggplot(df,aes(x = x, y = y)) +stat_density2d(geom = 'point', aes(size = ..density..),contour = FALSE) +
scale_size_area()
|