基于这个文档的数据用r语言 绘制OXY以及age列的散布图
时间: 2024-09-09 14:17:07 浏览: 94
可以使用R语言中的`ggplot2`包来绘制'OXY'与'age'两列数据的散点图,首先需要将提供的数据导入到R中,并使用`ggplot2`进行绘图。具体的代码如下:
```R
# 安装并加载ggplot2包
if (!require(ggplot2)) install.packages('ggplot2')
library(ggplot2)
# 将数据定义为一个data.frame对象
data <- data.frame(
num = 1:31,
age = c(57, 54, 52, 50, 51, 54, 51, 57, 49, 48, 52, 44, 45, 45, 47, 54, 49, 51, 51, 48, 49, 44, 40, 44, 42, 38, 47, 40, 43, 44, 38),
weight = c(73.37, 79.38, 76.32, 70.87, 67.25, 91.63, 73.71, 59.08, 76.32, 61.24, 82.78, 73.03, 87.66, 66.45, 79.15, 83.12, 81.42, 69.63, 77.91, 91.63, 73.37, 89.47, 75.07, 85.84, 68.15, 89.02, 77.45, 75.98, 81.19, 81.42, 81.87),
time = c(12.63, 11.17, 9.63, 8.92, 11.08, 12.88, 10.47, 9.93, 9.4, 11.5, 10.5, 10.13, 14.03, 11.12, 10.6, 10.33, 8.95, 10.95, 10, 10.25, 10.08, 11.37, 10.07, 8.65, 8.17, 9.22, 11.63, 11.95, 10.85, 13.08, 8.63),
spulse = c(58, 62, 48, 48, 48, 44, 59, 49, 56, 52, 53, 45, 56, 51, 47, 50, 44, 57, 48, 48, 76, 62, 62, 45, 40, 55, 58, 70, 64, 63, 48),
rPulse = c(174, 156, 164, 146, 172, 168, 186, 148, 186, 170, 170, 168, 186, 176, 162, 166, 180, 168, 162, 162, 168, 178, 185, 156, 166, 178, 176, 176, 176, 162, 170, 186),
mPulse = c(176, 165, 166, 155, 172, 172, 188, 155, 188, 176, 172, 168, 192, 176, 164, 170, 185, 172, 168, 164, 168, 182, 185, 168, 172, 180, 176, 180, 170, 176, 186),
OXY = c(39.407, 46.08, 45.441, 54.625, 45.118, 39.203, 45.79, 50.545, 48.673, 47.92, 47.467, 50.541, 37.388, 44.754, 47.273, 51.855, 49.156, 40.836, 46.672, 46.774, 50.388, 44.609, 45.313, 54.297, 59.571, 49.874, 44.811, 45.681, 49.091, 39.442, 60.055)
)
# 使用ggplot2创建散点图
p <- ggplot(data, aes(x=age, y=OXY))
p <- p + geom_point() # 添加散点
print(p) # 显示图表
```
上述代码将会生成一张以'age'为x轴,'OXY'为y轴的散点图,通过这张图表能够直观地看出年龄(age)和氧气消耗量(OXY)之间的关系。
阅读全文