ggplot2-qplot基本用法

install.packages("ggplot2")

library(ggplot2)

散点图:

plot(mtcars$wt,mtcars$mpg)

线图:

plot(pressure$temperature,pressure$pressure,type="l")

points(pressure$temperature,pressure$pressure)

lines(pressure$temperature,pressure$pressure/2,type="l",col="red")

points(pressure$temperature,pressure$pressure/2,col="red")

Bar图

barplot(table(mtcars$cyl))

Hist图

hist(mtcars$mpg,breks=10)

hist(mtcars$cyl,breks=10)

Box plot箱线图

boxplot(mtcars$mpg)

curve(x^2-5*x,from-4,to-4)

myfun<-function(xvar){1/(1+exp(-xvar+10))}

curve(myfun(x),from=0,to=20)

 

dat=diamonds

qplot(carat,price,data=diamonds)

qplot(log(carat),log(price),data=diamonds)

qplot(carat,x*y*z,data=diamonds)

#colour,size,shape

dsmall=diamonds[sample(nrow(diamonds),100),]

qplot(carat,price,data=dsmall,colour=color)

qplot(carat,price,data=dsmall,shape=cut)

#make a semi-transparent colour

qplot(carat,price,data=diamonds,alpha=I(1/100))

qplot(carat,price,data=diamonds,alpha=I(1/100))

qplot(carat,price,data=diamonds,alpha=I(1/200))

#

library(splines)

qplot(carat,price,data=dsmall,geom=c("point","smooth"),method="lm")

qplot(carat,price,data=dsmall,geom=c("point","smooth"),method="lm",formula=y~ns(x,5))

#

color,fill

qplot(color,price,data=dsmall,geom="boxplot")

qplot(color,price,data=dsmall,geom="boxplot",fill="blue")

qplot(color,price,data=dsmall,geom="boxplot",fill=blue)

qplot(color,price,data=dsmall,geom="boxplot",size=2)#size线的粗细

qplot(color,price,data=dsmall,geom="boxplot")+geom_boxplot(outlier.colour="green",outlier.size=10,fill="red",colour="blue",size=2)

qplot(carat,data=diamonds,geom="histogram",colour=color)

qplot(carat,data=diamonds,geom="density")

qplot(carat,data=diamonds,geom="histogram",fill=color)

 

posted @   ^_^Anne  阅读(79)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示