R可视化:ggpubr包学习

news2025/2/24 9:15:43

欢迎大家关注全网生信学习者系列:

  • WX公zhong号:生信学习者

  • Xiao hong书:生信学习者

  • 知hu:生信学习者

  • CDSN:生信学习者2

介绍

ggpubr是我经常会用到的R包,它傻瓜式的画图方式对很多初次接触R绘图的人来讲是很友好的。该包有个stat_compare_means函数可以做组间假设检验分析。

安装R包

install.packages("ggpubr")
devtools::devtools::install_github("kassambara/ggpubr")
library(ggpubr)
​
​
plotdata <- data.frame(sex = factor(rep(c("F", "M"), each=200)),
                   weight = c(rnorm(200, 55), rnorm(200, 58)))

密度图density

ggdensity(plotdata, 
          x = "weight",
          add = "mean", 
          rug = TRUE,    # x轴显示分布密度
          color = "sex", 
          fill = "sex",
          palette = c("#00AFBB", "#E7B800"))

柱状图histogram

gghistogram(plotdata, 
            x = "weight",
            bins = 30,
            add = "mean", 
            rug = TRUE,
            color = "sex", 
            fill = "sex",
            palette = c("#00AFBB", "#E7B800"))

箱线图boxplot

df <- ToothGrowth
head(df)
my_comparisons <- list( c("0.5", "1"), c("1", "2"), c("0.5", "2") )
ggboxplot(df, 
          x = "dose", 
          y = "len",
          color = "dose", 
          palette =c("#00AFBB", "#E7B800", "#FC4E07"),
          add = "jitter", 
          shape = "dose")+
  stat_compare_means(comparisons = my_comparisons)+ # Add pairwise comparisons p-value
  stat_compare_means(label.y = 50) 

小提琴图violin

ggviolin(df, 
         x = "dose", 
         y = "len", 
         fill = "dose",
         palette = c("#00AFBB", "#E7B800", "#FC4E07"),
         add = "boxplot", 
         add.params = list(fill = "white"))+
  stat_compare_means(comparisons = my_comparisons, label = "p.signif")+ # Add significance levels
  stat_compare_means(label.y = 50)  

点图dotplot

ggdotplot(ToothGrowth, 
          x = "dose", 
          y = "len",
          color = "dose", 
          palette = "jco", 
          binwidth = 1)

有序条形图 ordered bar plots

data("mtcars")
dfm <- mtcars
dfm$cyl <- as.factor(dfm$cyl)
dfm$name <- rownames(dfm)
head(dfm[, c("name", "wt", "mpg", "cyl")])
​
ggbarplot(dfm, 
          x = "name", y = "mpg",
          fill = "cyl",               # change fill color by cyl
          color = "white",            # Set bar border colors to white
          palette = "jco",            # jco journal color palett. see ?ggpar
          sort.val = "asc",           # Sort the value in dscending order
          sort.by.groups = TRUE,      # Sort inside each group
          x.text.angle = 90)          # Rotate vertically x axis texts

偏差图Deviation graphs

dfm$mpg_z <- (dfm$mpg -mean(dfm$mpg))/sd(dfm$mpg)
dfm$mpg_grp <- factor(ifelse(dfm$mpg_z < 0, "low", "high"), 
                      levels = c("low", "high"))
# Inspect the data
head(dfm[, c("name", "wt", "mpg", "mpg_z", "mpg_grp", "cyl")])
​
ggbarplot(dfm, x = "name", y = "mpg_z",
          fill = "mpg_grp",           # change fill color by mpg_level
          color = "white",            # Set bar border colors to white
          palette = "jco",            # jco journal color palett. see ?ggpar
          sort.val = "asc",           # Sort the value in ascending order
          sort.by.groups = FALSE,     # Don't sort inside each group
          x.text.angle = 90,          # Rotate vertically x axis texts
          ylab = "MPG z-score",
          rotate = FALSE,
          xlab = FALSE,
          legend.title = "MPG Group")

棒棒糖图 lollipop chart

ggdotchart(dfm, x = "name", y = "mpg",
           color = "cyl",                                # Color by groups
           palette = c("#00AFBB", "#E7B800", "#FC4E07"), # Custom color palette
           sorting = "descending",                       # Sort value in descending order
           add = "segments",                             # Add segments from y = 0 to dots
           rotate = TRUE,                                # Rotate vertically
           group = "cyl",                                # Order by groups
           dot.size = 6,                                 # Large dot size
           label = round(dfm$mpg),                       # Add mpg values as dot labels
           font.label = list(color = "white", size = 9, 
                             vjust = 0.5),               # Adjust label parameters
           ggtheme = theme_pubr())                       # ggplot2 theme

偏差图Deviation graph

ggdotchart(dfm, x = "name", y = "mpg_z",
           color = "cyl",                                # Color by groups
           palette = c("#00AFBB", "#E7B800", "#FC4E07"), # Custom color palette
           sorting = "descending",                       # Sort value in descending order
           add = "segments",                             # Add segments from y = 0 to dots
           add.params = list(color = "lightgray", size = 2), # Change segment color and size
           group = "cyl",                                # Order by groups
           dot.size = 6,                                 # Large dot size
           label = round(dfm$mpg_z,1),                   # Add mpg values as dot labels
           font.label = list(color = "white", size = 9, 
                             vjust = 0.5),               # Adjust label parameters
           ggtheme = theme_pubr())+                      # ggplot2 theme
  geom_hline(yintercept = 0, linetype = 2, color = "lightgray")

散点图scatterplot

df <- datasets::iris
head(df)
ggscatter(df, 
          x = 'Sepal.Width', 
          y = 'Sepal.Length', 
          palette = 'jco', 
          shape = 'Species', 
          add = 'reg.line',
          color = 'Species', 
          conf.int = TRUE)

  • 添加回归线的系数

ggscatter(df, 
          x = 'Sepal.Width', 
          y = 'Sepal.Length', 
          palette = 'jco', 
          shape = 'Species', 
          add = 'reg.line',
          color = 'Species', 
          conf.int = TRUE)+
  stat_cor(aes(color=Species),method = "pearson", label.x = 3)

  • 添加聚类椭圆 concentration ellipses

data("mtcars")
dfm <- mtcars
dfm$cyl <- as.factor(dfm$cyl)
dfm$name <- rownames(dfm)
​
p1 <- ggscatter(dfm, 
          x = "wt", 
          y = "mpg",
          color = "cyl", 
          palette = "jco",
          shape = "cyl",
          ellipse = TRUE)
p2 <- ggscatter(dfm, 
                x = "wt", 
                y = "mpg",
                color = "cyl", 
                palette = "jco",
                shape = "cyl",
                ellipse = TRUE,
                ellipse.type = "convex")
cowplot::plot_grid(p1, p2, align = "hv", nrow = 1)

  • 添加mean和stars

ggscatter(dfm, x = "wt", y = "mpg",
          color = "cyl", palette = "jco",
          shape = "cyl",
          ellipse = TRUE, 
          mean.point = TRUE,
          star.plot = TRUE)

  • 显示点标签

dfm$name <- rownames(dfm)
p3 <- ggscatter(dfm, 
          x = "wt", 
          y = "mpg",
          color = "cyl", 
          palette = "jco",
          label = "name",
          repel = TRUE)
p4 <- ggscatter(dfm, 
                x = "wt", 
                y = "mpg",
                color = "cyl", 
                palette = "jco",
                label = "name",
                repel = TRUE,
                label.select = c("Toyota Corolla", "Merc 280", "Duster 360"))
cowplot::plot_grid(p3, p4, align = "hv", nrow = 1)

气泡图bubble plot

ggscatter(dfm, 
          x = "wt", 
          y = "mpg",
          color = "cyl",
          palette = "jco",
          size = "qsec", 
          alpha = 0.5)+
  scale_size(range = c(0.5, 15))    # Adjust the range of points size

连线图 lineplot

p1 <- ggbarplot(ToothGrowth, 
          x = "dose", 
          y = "len", 
          add = "mean_se",
          color = "supp", 
          palette = "jco", 
          position = position_dodge(0.8))+
  stat_compare_means(aes(group = supp), label = "p.signif", label.y = 29)
p2 <- ggline(ToothGrowth, 
       x = "dose", 
       y = "len", 
       add = "mean_se",
       color = "supp", 
       palette = "jco")+
  stat_compare_means(aes(group = supp), label = "p.signif", 
                     label.y = c(16, 25, 29))
cowplot::plot_grid(p1, p2, ncol = 2, align = "hv")

添加边沿图 marginal plots

library(ggExtra)
p <- ggscatter(iris, 
               x = "Sepal.Length", 
               y = "Sepal.Width",
               color = "Species", 
               palette = "jco",
               size = 3, 
               alpha = 0.6)
ggMarginal(p, type = "boxplot")

  • 第二种添加方式: 分别画出三个图,然后进行组合

sp <- ggscatter(iris, 
                x = "Sepal.Length", 
                y = "Sepal.Width",
                color = "Species", 
                palette = "jco",
                size = 3, 
                alpha = 0.6, 
                ggtheme = theme_bw())             
​
xplot <- ggboxplot(iris, 
                   x = "Species", 
                   y = "Sepal.Length", 
                   color = "Species", 
                   fill = "Species", 
                   palette = "jco",
                   alpha = 0.5, 
                   ggtheme = theme_bw())+ rotate()
​
yplot <- ggboxplot(iris, 
                   x = "Species", 
                   y = "Sepal.Width",
                   color = "Species", 
                   fill = "Species", 
                   palette = "jco",
                   alpha = 0.5, 
                   ggtheme = theme_bw())
​
​
sp <- sp + rremove("legend")
yplot <- yplot + clean_theme() + rremove("legend")
xplot <- xplot + clean_theme() + rremove("legend")
cowplot::plot_grid(xplot, NULL, sp, yplot, ncol = 2, align = "hv", 
          rel_widths = c(2, 1), rel_heights = c(1, 2))

  • 上图主图和边沿图之间的space太大,第三种方法能克服这个缺点

library(cowplot) 
# Main plot
pmain <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species))+
  geom_point()+
  ggpubr::color_palette("jco")
​
# Marginal densities along x axis
xdens <- axis_canvas(pmain, axis = "x")+
  geom_density(data = iris, aes(x = Sepal.Length, fill = Species),
               alpha = 0.7, size = 0.2)+
  ggpubr::fill_palette("jco")
​
# Marginal densities along y axis
# Need to set coord_flip = TRUE, if you plan to use coord_flip()
ydens <- axis_canvas(pmain, axis = "y", coord_flip = TRUE)+
  geom_boxplot(data = iris, aes(x = Sepal.Width, fill = Species),
               alpha = 0.7, size = 0.2)+
  coord_flip()+
  ggpubr::fill_palette("jco")
​
p1 <- insert_xaxis_grob(pmain, xdens, grid::unit(.2, "null"), position = "top")
p2 <- insert_yaxis_grob(p1, ydens, grid::unit(.2, "null"), position = "right")
ggdraw(p2)

  • 第四种方法,通过grob设置

# Scatter plot colored by groups ("Species")
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
sp <- ggscatter(iris, x = "Sepal.Length", y = "Sepal.Width",
                color = "Species", palette = "jco",
                size = 3, alpha = 0.6)
# Create box plots of x/y variables
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Box plot of the x variable
xbp <- ggboxplot(iris$Sepal.Length, width = 0.3, fill = "lightgray") +
  rotate() +
  theme_transparent()
# Box plot of the y variable
ybp <- ggboxplot(iris$Sepal.Width, width = 0.3, fill = "lightgray") +
  theme_transparent()
# Create the external graphical objects
# called a "grop" in Grid terminology
xbp_grob <- ggplotGrob(xbp)
ybp_grob <- ggplotGrob(ybp)
# Place box plots inside the scatter plot
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
xmin <- min(iris$Sepal.Length); xmax <- max(iris$Sepal.Length)
ymin <- min(iris$Sepal.Width); ymax <- max(iris$Sepal.Width)
yoffset <- (1/15)*ymax; xoffset <- (1/15)*xmax
# Insert xbp_grob inside the scatter plot
sp + annotation_custom(grob = xbp_grob, xmin = xmin, xmax = xmax, 
                       ymin = ymin-yoffset, ymax = ymin+yoffset) +
  # Insert ybp_grob inside the scatter plot
  annotation_custom(grob = ybp_grob,
                       xmin = xmin-xoffset, xmax = xmin+xoffset, 
                       ymin = ymin, ymax = ymax)

二维密度图 2d density

sp <- ggscatter(iris, x = "Sepal.Length", y = "Sepal.Width",
                color = "lightgray")
p1 <- sp + geom_density_2d()
# Gradient color
p2 <- sp + stat_density_2d(aes(fill = ..level..), geom = "polygon")
# Change gradient color: custom
p3 <- sp + stat_density_2d(aes(fill = ..level..), geom = "polygon")+
  gradient_fill(c("white", "steelblue"))
# Change the gradient color: RColorBrewer palette
p4 <- sp + stat_density_2d(aes(fill = ..level..), geom = "polygon") +
  gradient_fill("YlOrRd")
​
cowplot::plot_grid(p1, p2, p3, p4, ncol = 2, align = "hv")

混合图

混合表、字体和图

# Density plot of "Sepal.Length"
#::::::::::::::::::::::::::::::::::::::
density.p <- ggdensity(iris, x = "Sepal.Length", 
                       fill = "Species", palette = "jco")
# Draw the summary table of Sepal.Length
#::::::::::::::::::::::::::::::::::::::
# Compute descriptive statistics by groups
stable <- desc_statby(iris, measure.var = "Sepal.Length",
                      grps = "Species")
stable <- stable[, c("Species", "length", "mean", "sd")]
# Summary table plot, medium orange theme
stable.p <- ggtexttable(stable, rows = NULL, 
                        theme = ttheme("mOrange"))
# Draw text
#::::::::::::::::::::::::::::::::::::::
text <- paste("iris data set gives the measurements in cm",
              "of the variables sepal length and width",
              "and petal length and width, respectively,",
              "for 50 flowers from each of 3 species of iris.",
             "The species are Iris setosa, versicolor, and virginica.", sep = " ")
text.p <- ggparagraph(text = text, face = "italic", size = 11, color = "black")
# Arrange the plots on the same page
ggarrange(density.p, stable.p, text.p, 
          ncol = 1, nrow = 3,
          heights = c(1, 0.5, 0.3))

  • 注释table在图上

density.p <- ggdensity(iris, x = "Sepal.Length", 
                       fill = "Species", palette = "jco")
​
stable <- desc_statby(iris, measure.var = "Sepal.Length",
                      grps = "Species")
stable <- stable[, c("Species", "length", "mean", "sd")]
stable.p <- ggtexttable(stable, rows = NULL, 
                        theme = ttheme("mOrange"))
density.p + annotation_custom(ggplotGrob(stable.p),
                              xmin = 5.5, ymin = 0.7,
                              xmax = 8)

systemic information

sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
​
Matrix products: default
​
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936  LC_CTYPE=Chinese (Simplified)_China.936   
[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C                              
[5] LC_TIME=Chinese (Simplified)_China.936    
​
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
​
other attached packages:
[1] ggpubr_0.4.0  ggplot2_3.3.2
​
loaded via a namespace (and not attached):
 [1] zip_2.0.4         Rcpp_1.0.3        cellranger_1.1.0  pillar_1.4.6      compiler_3.6.1    forcats_0.5.0    
 [7] tools_3.6.1       digest_0.6.27     lifecycle_0.2.0   tibble_3.0.4      gtable_0.3.0      pkgconfig_2.0.3  
[13] rlang_0.4.8       openxlsx_4.2.3    ggsci_2.9         rstudioapi_0.10   curl_4.3          haven_2.3.1      
[19] rio_0.5.16        withr_2.1.2       dplyr_1.0.2       generics_0.0.2    vctrs_0.3.4       hms_0.5.3        
[25] grid_3.6.1        tidyselect_1.1.0  glue_1.4.2        data.table_1.13.2 R6_2.4.1          rstatix_0.6.0    
[31] readxl_1.3.1      foreign_0.8-73    carData_3.0-4     farver_2.0.3      tidyr_1.0.0       purrr_0.3.3      
[37] car_3.0-10        magrittr_1.5      scales_1.1.0      backports_1.1.10  ellipsis_0.3.1    abind_1.4-5      
[43] colorspace_1.4-1  ggsignif_0.6.0    labeling_0.4.2    stringi_1.4.3     munsell_0.5.0     broom_0.7.2      
[49] crayon_1.3.4

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1824302.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

GO RACE 测试在低版本GCC上报错误 exit status 0xc0000139

windows机器环境&#xff0c;go程序使用race定位时一运行就报错&#xff0c;写了个example如&#xff1a; 能看到加了race之后就不行了&#xff0c; 搜了一下&#xff0c;git上有个issue&#xff1a; runtime: Race detector causes exit status 0xc0000139 on Windows 11 wi…

高考志愿填报选专业,兴趣爱好和就业前景哪个优先?

每个人都有自己的兴趣与爱好&#xff0c;而高考志愿填报是在为自己选择职业方向。最理想的状态就是把自己的兴趣和爱好与自己的职业统一起来&#xff0c;让兴趣和爱好促进职业的发展&#xff0c;为职业增添动力。但现实生活中&#xff0c;这种理想的状态并不是每个人都能达到的…

Java多线程面试重点-2

16.Synchronized关键字加在静态方法和实例方法的区别? 修饰静态方法&#xff0c;是对类进行加锁&#xff08;Class对象&#xff09;&#xff0c;如果该类中有methodA和methodB都是被Synch修饰的静态方法&#xff0c;此时有两个线程T1、T2分别调用methodA()和methodB()&#x…

http穿透怎么做?

众所周知http协议的默认端口是80&#xff0c;由于国家工信部要求&#xff0c;域名必须备案才给开放80端口&#xff0c;而备案需要固定公网IP&#xff0c;这就使得开放http80端口的费用成本和时间成本变的很高。那么能不能利用内网穿透技术做http穿透呢&#xff1f;下面我就给大…

Stability AI最新的SD3模型存在严重问题 为规避裸体结果导致躯体部分错乱

人工智能 Stability AI 最新的 SD3 Medium 模型存在严重问题&#xff0c;只要生成人物就会出现躯体错乱&#xff0c;这似乎是该公司刻意规避生成裸体图片的结果。目前猜测他们可能在训练过程中就剔除了 NSFW 内容&#xff0c;同时在训练时规避裸体内容进而导致模型也会刻意将人…

Haption Virtuose 6D力反馈设备遥操作机器人应用研究

在虚拟现实和远程操作技术的飞速发展下&#xff0c;力反馈设备成为了一个不可或缺的工具。其中&#xff0c;Haption Virtuose 6D力反馈设备以其卓越的性能和广泛的应用领域&#xff0c;成为了这一领域的佼佼者。本文将详细介绍Haption Virtuose 6D力反馈设备及其在遥操作机器人…

Flutter系列:关于ensureInitialized()

Flutter系列 关于ensureInitialized() - 文章信息 - Author: 李俊才 (jcLee95) Visit me at CSDN: https://jclee95.blog.csdn.netMy WebSite&#xff1a;http://thispage.tech/Email: 291148484163.com. Shenzhen ChinaAddress of this article:https://blog.csdn.net/qq_28…

RBAC权限实战

一、项目结构说明、搭建以及初步验证 引入SSM框架依赖: <dependencies> <dependency> <groupId>javax.servlet…

原型模式(大话设计模式)C/C++版本

原型模式 C 参考&#xff1a;https://www.cnblogs.com/Galesaur-wcy/p/15924300.html #include <iostream> #include <string> using namespace std;class WorkExprerience { private:string workDate;string company;public:WorkExprerience() {}~WorkExprerie…

《站在2024年的十字路口:计算机专业是否仍是高考生的明智之选?》

文章目录 每日一句正能量前言行业竞争现状行业饱和度和竞争激烈程度[^3^]新兴技术的影响[^3^]人才需求的变化[^3^]行业创新动态如何保持竞争力 专业与个人的匹配度判断专业所需的技术能力专业核心课程对学生的要求个人兴趣和性格特点专业对口的职业发展要求实践和经验个人价值观…

redis的四种模式部署应用

这里写目录标题 redis应用redis单机部署redis主从redis哨兵Cluster模式 redis应用 redis单机部署 关闭防火墙[rootzyq ~]#: yum -y install wget make gcc gcc-c ...... [rootzyq ~]#: wget https://download.redis.io/redis-stable.tar.gz --2024-01-01 19:41:14-- https:/…

qemu创建kvm虚拟机-x86模拟arm

1、虚拟机环境 虚拟机ubuntu22.042、下载需要的依赖 apt install openssh-server net-tools vim -yapt install qemu qemu-kvm qemu-system-arm bridge-utils uml-utilities qemu-efi-aarch64 cloud-image-utils -y#查看版本 qemu-img -V(1) 下载uefi固件 cd /optwget https…

tcp协议机制的总结(可靠性,提高性能),基于tcp的应用层协议,用udp如何实现可靠传输

目录 总结 引入 可靠性 ​编辑 分析 三次握手 提高性能 其他 常见的基于tcp应用层协议 用udp实现可靠传输 总结 引入 为什么tcp要比udp复杂的多? 因为它既要保证可靠性,又要兼顾性能 可靠性 分析 其中,序列号不止用来排序,还可以用在重传时去重 确认应答是机制中的…

中小制造业工厂要不要上MES系统

MES系统的主要功能包括制造数据管理、计划排产管理、生产调度管理、库存管理、质量管理、人力资源管理、工作中心/设备管理、工具工装管理、采购管理、成本管理、项目看板管理、生产过程控制、底层数据集成分析、上层数据集成分解等。通过这些模块&#xff0c;MES为企业打造一个…

前端菜鸡流水账日记 -- pnpm的学习

哈咯哇大家&#xff0c;我又来了&#xff0c;最近稍微悠闲一些&#xff0c;所以就趁着这个机会学习一些新的知识&#xff0c;今天就是碰巧遇到了pnm&#xff0c;这个可以看作是npm的升级版本&#xff0c;比npm要快&#xff0c;用起来也更得劲更迅速 官网地址&#xff1a;https…

Java ORM 双雄:Mybatis vs Hibernate 的技术对决

引言&#xff1a;本文将对 MyBatis 和H ibernate 进行全面比较&#xff0c;探讨它们在各个方面的异同以及在实际项目中的应用场景。我们将从基本概念、工作原理、配置方式、性能表现、灵活性、学习曲线等多个方面进行比较&#xff0c;帮助读者更好地理解并选择适合自己项目需求…

每日一题——Python实现PAT乙级1028 人口普查 Keyboard(举一反三+思想解读+逐步优化)六千字好文

一个认为一切根源都是“自己不够强”的INTJ 个人主页&#xff1a;用哲学编程-CSDN博客专栏&#xff1a;每日一题——举一反三Python编程学习Python内置函数 Python-3.12.0文档解读 目录 题目链接​编辑我的写法 专业点评 时间复杂度分析 空间复杂度分析 总结 我要更强…

Windows 11 中安装 Docker Desktop 并安装镜像

本该主要介绍在 Windows 11 中安装 Docker Desktop 时的一些准备工作&#xff0c;以及该如何下载和安装&#xff0c;然后分别使用管理界面和 Docker 命令安装两个镜像。 一、准备工作 在 Windows 11 中安装 Docker Desktop 前&#xff0c;需要做一些准备。打开 【Windows 功能…

R语言数据分析案例28-对数据集可视化和T检验

一、分析主题&#xff1a; 本分析旨在对数据集进行可视化和 T 检验&#xff0c;以探索数据集中的变量之间的关系和差异。通过可视化数据&#xff0c;我们可以直观地了解数据的分布和趋势&#xff0c;而 T 检验则可以帮助我们确定这些差异是否具有统计学意义。 二、具体分析 …

【CS.AL】算法必学之贪心算法:从入门到进阶 —— 关键概念和代码示例

文章目录 1. 概述2. 适用场景3. 设计步骤4. 优缺点5. 典型应用6. 题目和代码示例6.1 简单题目&#xff1a;找零问题6.2 中等题目&#xff1a;区间调度问题6.3 困难题目&#xff1a;分数背包问题 7. 题目和思路表格8. 总结References 1000.1.CS.AL.1.4-核心-GreedyAlgorithm-Cre…