js css html

4. 关于ggplot绘图公式复盘的一些问题3

2022-09-04  本文已影响0人  心惊梦醒

Time series with line and path plots

reorder(x, X, FUN = mean, ...,order = is.ordered(x))
- 第一个参数x为一个atomic vector
- 第二个参数X为与x等长的向量
- 第三个参数FUN为统计函数
- 第四个参数为传递给FUN的其他参数
- 第五个参数order为是否返回ordered factor,默认与x相同
举例说明:
ggplot(mpg, aes(reorder(class, hwy), hwy)) + geom_boxplot()
reoder()根据class将hwy分为若干个子集,对每个子集应用mean函数,最后根据计算得到的平均值对class进行排序

Beautiful!!!

g <- ggplot(mpg, aes(class))
p1 <- g + geom_bar()
p2 <- g + geom_bar(aes(weight = displ))
library(tidyverse)
aaa <- mpg %>% group_by(class) %>% summarise(www=sum(displ))
p3<- ggplot(aaa,aes(class,www)) + geom_bar(stat="identity")
ggpubr::ggarrange(p1,p2,p3,ncol=1)
# p2和p3的效果是一样的
上一篇 下一篇

猜你喜欢

热点阅读