美文网首页
ggplot2 geom函数第一讲geom_abline、geo

ggplot2 geom函数第一讲geom_abline、geo

作者: 生信斑马鱼 | 来源:发表于2022-11-09 00:49 被阅读0次

参考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)
image.png

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
count 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")
stack identity identity透明 fill dodge

相关文章

网友评论

      本文标题:ggplot2 geom函数第一讲geom_abline、geo

      本文链接:https://www.haomeiwen.com/subject/fadotdtx.html