# 1) 先画基础曲线:temperature(横轴) vs pressure(纵轴)plot( x = pressure$temperature, # 横轴:温度 y = pressure$pressure, # 纵轴:压力 type = "l", # type="l" 表示先画“线”(不画点) xlab = "temperature", # 横轴标签(可选) ylab = "pressure", # 纵轴标签(可选) main = "Pressure vs Temperature" # 图标题(可选))# 2) 在原始曲线上叠加点(与上面那条线对应)points( x = pressure$temperature, # 横轴 y = pressure$pressure, # 纵轴 pch = 19, # 点形状:19 为实心圆(可调整) col = "black" # 点颜色(可调整))# 3) 再叠加一条“缩放后的线”:压力的一半(pressure/2)# 这会画在与原曲线不同的纵轴位置(y 变为 pressure 的一半)lines( x = pressure$temperature, # 横轴 y = pressure$pressure / 2, # 纵轴:压力的一半 col = "red", # 线颜色 lwd = 2 # 线宽(可调整))# 4) 在红色那条线对应的位置再叠加点points( x = pressure$temperature, # 横轴 y = pressure$pressure / 2, # 纵轴:压力的一半 pch = 19, # 点形状 col = "red" # 点颜色)
ggplot(pressure, aes(x = temperature, y = pressure)) +
geom_line() +
geom_point() +
geom_line(aes(x = temperature, y = pressure/2), color="red") +
geom_point(aes(y = pressure/2), color = "red")
发表评论