参考https://ggplot2.tidyverse.org/reference/
1.geom_abline和geom_hline
ggplot(mtcars) +
geom_point(aes(mpg, disp, colour = gear)) +
theme_bw()+
geom_hline(yintercept = c(300, 400), colour = 'red', linetype = 2, size = 2) +
geom_vline(xintercept = c(20, 25), colour = 'blue', linetype = 3, size = 3)
2.geom_bar和geom_col
2.1 count or weight 数量或权重
g <- ggplot(mpg, aes(class))
g + geom_bar() #count
g + geom_bar(aes(weight = displ)) #weight
2.2 方向,把数据赋值给y,则转为横向
ggplot(mpg) + geom_bar(aes(y = class))
2.3 position
p <- ggplot(data = diamonds, mapping = aes(x = cut, fill = clarity))
#default position stack
p + geom_bar()
#identity由于遮挡问题不适合做bar图
p + geom_bar(position = "identity")
p + geom_bar(position = "identity", fill = NA, aes(colour = clarity))
p + geom_bar(position = "fill")
p + geom_bar(position = "dodge")