R如何用ggplot画图

加载ggplot2: library(‘ggplot2’)
1.条形图
基本命令:qplot(region, data = example1, geom = ‘bar’)
将标题居中放置:theme_update(plot.title = element_text(hjust = 0.5))
qplot(region, data=example1, geom=‘bar’, main=‘标题’, ylab=‘count’)
2.直方图
基本命令:qplot(Price, data=example1, geom=‘histogram’)
调整宽度:
qplot(Price, data=example1, geom=‘histogram’, binwidth=5)
qplot(Price, data=example1, geom=‘histogram’, binwidth=5,
main=‘标题’, ylab=‘frequency’)
调整坐标轴范围:
qplot(Price, data=example1, geom=‘histogram’, binwidth=5,
main=‘标题’, ylab=‘frequency’, xlim=c(0,8), ylim=c(0,5))
填充颜色:
qplot(Price, data=example1, geom=‘histogram’, binwidth=5,
main=‘标题’, ylab=‘frequency’, fill=I(‘blue’))
添加边框颜色:
qplot(Price, data=example1, geom=‘histogram’, binwidth=5,
main=‘标题’, ylab=‘frequency’, fill=I(‘sky blue’), col=I(‘red’))
调整透明度:
qplot(Price, data=example1, geom=‘histogram’, binwidth=5,
main=‘标题’, ylab=‘frequency’, fill=I(‘blue’), alpha=I(0.8))
3.箱线图
qplot(x=“1”, y=Price, data=example1, geom=‘boxplot’)
qplot(x=“1”, y=Price, data=example1, geom=‘boxplot’, xlab=‘Price’)
qplot(x=region, y=Price, data=example1, geom=‘boxplot’)
qplot(x=region, y=Price, data=example1, geom=‘boxplot’, fill=region)
qplot(x=region, y=Price, data=example1, geom=‘boxplot’, fill=region, outlier.shape=NA)
qplot(x=region, y=Price, data=example1, geom=c(‘boxplot’,‘jitter’), fill=region, outlier.shape=NA)
4.散点图
qplot(x=Kilogram, y=Price, data=example1, geom=‘point’)
qplot(x=Kilogram, y=Price, data=example1, geom=‘point’, ylab=‘Price’)
调整散点大小:
qplot(x=Kilogram, y=Price, data=example1, geom=‘point’, ylab=‘Price’,size=I(3))
调整散点形状:
qplot(x=Kilogram, y=Price, data=example1, geom=‘point’, ylab=‘Price’, shape=I(‘triangle’))
qplot(x=Kilogram, y=Price, data=example1, geom=‘point’, ylab=‘Price’, col=Region)
qplot(x=Kilogram, y=Price, data=example1, geom=‘point’, ylab=‘Price’, col=Region, shape=region)
5.分组画图
qplot(x=Kilogram, y=Price, data=example1, geom=‘point’, ylab=‘Price’, facets=Region~Sex)
qplot(x=Kilogram, y=Price, data=example1, geom=‘point’, ylab=‘Price’, facets=Region~.)
qplot(x=Kilogram, y=Price, data=example1, geom=‘point’, ylab=‘Price’, facets=.~Sex)
qplot(x=Kilogram, y=Price, data=example1, geom=‘point’, ylab=‘Price’, facets=.~Sex, col=region)
qplot(x=Sex, y=Price, data=example1, geom=‘boxplot’, fill=Sex)
qplot(x=Sex, y=Price, data=example1, geom=‘boxplot’, fill=Sex, facets=.~Region)
qplot(x=Sex, y=Price, data=example1, geom=‘boxplot’, fill=Sex, facets=.~Region, main=‘Age by Sex and Region’)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值