Lesson6

2023-12-18 22:48:30 浏览数 (1)


title: "lesson6"

output: html_document

date: "2023-12-18"


代码语言:{r setup, include=FALSE}复制
knitr::opts_chunk$set(echo = TRUE)

当堂作业boxplot

run一下这三个代码看一下区别

代码语言:text复制
library(ggplot2)
ggplot(data = iris)  
     geom_boxplot(mapping = aes(x = Species, y = Sepal.Width, color =                                    Species))
代码语言:text复制
ggplot(data = iris)  
     geom_boxplot(mapping = aes(x = Species, y = Sepal.Width, color =                                    Species, fill = Species))
代码语言:text复制
ggplot(data = iris)  
     geom_boxplot(mapping = aes(x = Species, y = Sepal.Width, fill =                                     Species))

boxplot线默认就是黑色的,如果改填充色直接改fill就好了

图层的叠放顺序和代码存在关联,最后一行代码在最上面的图层

思路:先排框架 “ ”用来分隔函数(或者理解为分隔图层)

代码语言:text复制
#局部分别设置
ggplot(data = iris) 
  geom_violin(mapping = aes(x = Sepal.Width, y = Species, fill = Species)) 
  geom_boxplot(mapping = aes(x = Sepal.Width, y = Species)) 
  geom_jitter(mapping = aes(x = Sepal.Width, y = Species, shape = Species))
代码语言:text复制
#先全局后局部
ggplot(data = iris, mapping = aes(x = Sepal.Width, y = Species)) 
         geom_violin(mapping = aes(fill = Species)) 
         geom_boxplot() 
         geom_jitter(mapping = aes(shape = Species))
代码语言:text复制
#单个图层手动修改指定
ggplot(data = iris, mapping = aes(x = Sepal.Width, y = Species)) 
                geom_violin(mapping = aes(fill = Species)) 
                geom_boxplot() 
                geom_jitter(mapping = aes(shape = Species))  
                            scale_shape_manual(values = c(1,5,8))

ggpubr中comparison的传递要求是列表,格式要求严格

好像上课的时候有点啥疑问但是又忘了 最近正好做到这里,实践的时候再看

0 人点赞