Python总结

#(1)美观
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, color = class, size = class,
alpha = class, shape = size, color = displ < 5))
参数在aes()内,是根据class分组确定颜色,大小,透明度和形状。参数在aes()外,是对整个图形改变,如ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy), color = “blue”)

#(2)分面
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy)) +
facet_wrap(~ class, nrow = 2)

ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy)) +
facet_grid(drv ~ cyl)
在这里插入图片描述

以下代码会绘制出什么图? . 的作用是什么?
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy)) +
facet_grid(drv ~ .)
在这里插入图片描述

ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy)) +
facet_grid(. ~ cyl)

#(3)集合对象
ggplot(data = mpg) +
geom_smooth(mapping = aes(x = displ, y = hwy, linetype = drv, group = drv),
show.legend = FALSE, data = filter(mpg, class = “subcompact”),
se = FALSE, method = lm)
linetype是线的形状,group是分组参数,show.legend是展示图例, F是不展示,se是置信区间参数,F是不展示。data = filter(mpg, class = “subcompact”)是筛选class == "subcompact"的数据作曲线图。method = lm是画出回归直线。

#(4)统计变化
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, color = cut, fill = cut/clarity), stat = “identity”)
color是改变边框颜色,fill=cut是填充bar的颜色,clarity是填充颜色堆叠画图,stat表示对样本点做统计的方式,默认是identity,表示一个x对应一个y
ggplot(data = diamonds) +
stat_count(mapping = aes(x = cut))

在这里插入图片描述
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, y = …prop…, group = 1))

没有group使得每个bar的高度都为1。
ggplot(data = diamonds) +
geom_bar(
mapping = aes(x = cut, fill = clarity),
position = “identity”/“fill”/“dodge”/“jitter”
)
position默认为identity,是展示全部对象;fill是每个bar都相同高度,dodge是更具分类展示每个bar,jitter是对图加入扰动噪声。

#(5)坐标系
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = cut), show.legend = FALSE, width = 1) +
theme(aspect.ratio = 1) +
labs(x = NULL, y = NULL) +
coord_flip() +
coord_polar()

使用 coord_polar() 函数将堆叠式条形图转换为饼图。
ggplot(mpg, aes(x = factor(1), fill = drv)) +
geom_bar(width = 1) +
coord_polar(theta = “y”)
在这里插入图片描述
ggplot(data = mpg, mapping = aes(x = cty, y = hwy)) +
geom_point() +
geom_abline() +
coord_fixed()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值