R循环作图拼图

12 篇文章 2 订阅
7 篇文章 0 订阅
library(testpackage)
kmeans_test_data <- kmeans_test_data
kmeans_test_group <- kmeans_test_group
data <- testpackage::means_calculate(kmeans_test_data,
                                     kmeans_test_group)
testpackage::kmeans_plot(data,
                         centers = 15,
                         row = 3,
                         col = 5,
                         center_col = "blue",
                         las = 2)
df <- kmeans_plot(data,
                  centers = 15,
                  row = 3,
                  col = 5,
                  center_col = "blue",
                  las = 2)
library(reshape2)
df2 <- melt(df)
ggplot(df2[which(df2$Cluster == 'cluster2'),],
       aes(x = variable, 
           y = value,
           group =meta ))+
  geom_line()
  
plot_list = list()
for (i in 1:15) {
  p <- ggplot(df2[which(df2$Cluster == paste0('cluster',i)),],
         aes(x = variable, 
             y = value,
             group =meta ))+
    geom_line(col = "blue")+
    labs(x= "xlab",y = "ylab")+
    theme_bw()
  plot_list[[i]] = p
}
plot_list[1]
plot_list[2]
plot_list[3]
library(patchwork)
wrap_plots(plot_list, byrow = T, nrow = 5)
library(cowplot)
plot_grid(plotlist = plot_list, align = "h", 
          nrow = 3)

在这里插入图片描述

for (i in 1:15) {
  assign(paste("p",i,sep=""),ggplot(df2[which(df2$Cluster == paste0('cluster',i)),],
                                    aes(x = variable, 
                                        y = value,
                                        group =meta ))+
           geom_line(col = "blue")+
           labs(x= "xlab",y = "ylab")+
           theme_bw())
}


p1+p2+p3+p4+p5+p6+p7+p8+p9

在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值