R可视化和ggplot2

《R数据可视化手册》学习笔记5---散点图(2)映射3个连续型变

2023-09-24  本文已影响0人  RSP小白之路

写在前面。


映射3个连续型变量的散点图

如何使用点的颜色或者大小属性刻画第三个连续型变量?

将连续型变量映射给size或者colour即可。

示例数据heightweight数据集中的4列。

> head(heightweight[,c("sex","ageYear","heightIn","weightLb")])
  sex ageYear heightIn weightLb
1   f   11.92     56.3     85.0
2   f   12.92     62.3    105.0
3   f   12.75     63.3    108.0
4   f   13.42     59.0     92.0
5   f   15.92     62.5    112.5
6   f   14.25     62.5    112.0
ggplot(data = heightweight, aes( x = ageYear , y = heightIn, colour=weightLb)) +geom_point()

[图片上传失败...(image-5a8675-1695604617115)]

ggplot(data = heightweight,  aes( x = ageYear , y = heightIn, size=weightLb)) +geom_point()

[图片上传失败...(image-716b15-1695604617115)]


以上。

上一篇 下一篇

猜你喜欢

热点阅读