#散点图
head(mtcars)
plot(mtcars$wt,mtcars$mpg)#基础绘图系统得到的散点图
#ggplot中qplot()函数得到的散点图得同样图
install.packages("ggplot2")
#若两参数向量在同一数据框内
qplot(wt,mpg,data=mtcars)
#等价于
ggplot(mtcars,aes(x=wt,y=mpg))+geom_point()
#折线图(type="l"为线性)
head(pressure)
plot(pressure$temperature,pressure$pressure,type="l")#绘出第一条折线
#向图形中添加数据点或多条折线
points(pressure$temperature,pressure$pressure)#添加数据点
lines(pressure$temperature,pressure$pressure/2,col="red")#添加更多折线
points(pressure$temperature,pressure$pressure/2,col="red")
#ggplot2中qplot()函数绘制折线图
qplot(pressure$temperature,pressure$pressure,geom="line")
#等价于
qplot(temperature,pressure,data=pressure,geom="line")
#等价于
ggplot(pressure,aes(x=temperature,y=pressure))+geom_line()