R图 连续变量-作图

install.packages("ggExtra")
library(ggExtra)

piris <- ggplot(iris, aes(Sepal.Length, Sepal.Width, 
                          color = Species)) +
  geom_point(shape=21, size = 3,stroke = 1.2)+
  scale_color_npg()+
  theme_bw()+
  theme(legend.position = c(.1,.86))
ggMarginal(piris, type= 'density',
           groupFill = TRUE)

R图 连续变量-作图_第1张图片

相关系数:

install.packages("ggcorrplot")
library(ggcorrplot)

mtcars2 <- mtcars %>% select(c('mpg','disp','hp',
                              'drat','wt','qsec'))
corr <- round(cor(mtcars2), 1)
corr
p1 <- ggcorrplot(corr, method = 'square')

p2 <- ggcorrplot(corr, method = "circle")

plot_grid(p1,p2,ncol=2,labels = LETTERS[1:2],align = c('v','h'))

R图 连续变量-作图_第2张图片

相关系数

p1 <- ggcorrplot(
  corr,
  type = "lower",
  outline.color = "white",
  colors = c("#6D9EC1", "white", "#E46726")
)

p2 <- ggcorrplot(
  corr,
  type = "upper",
  outline.color = "white",
  colors = c("#084594", "white", "#ef3b2c")
)

p3 <- ggcorrplot(corr,
                 type = "lower",
                 lab = TRUE)

p.mat <- cor_pmat(mtcars2)

p4 <- ggcorrplot(corr,
                 type = "lower",
                 p.mat = p.mat)

plot_grid(p1,p2,p3,p4,ncol=2,labels = LETTERS[1:4],align = c('v','h'))

R图 连续变量-作图_第3张图片

生存曲线

install.packages("survminer")
library(survminer)
library(survival)

p2 <- ggsurvplot(
  fit, 
  data = lung, 
  size = 1,                
  palette = c("#E7B800", "#2E9FDF"),
  conf.int = TRUE,          
  pval = TRUE,              
  risk.table = TRUE,        
  risk.table.col = "strata",
  legend.labs = 
    c("Male", "Female"),    
  risk.table.height = 0.25, 
  ggtheme = theme_bw(),
  legend.title = 'Sex',
  legend = c(.85,.8)
)

R图 连续变量-作图_第4张图片

你可能感兴趣的:(R,r语言,开发语言,机器学习)