pheatmap(hmExp, + annotation_col =Type, + color <- colorRampPalette(c("blue", "white", "red"))(50) + cluster_cols =F, Error: unexpected symbol in: " color <- colorRampPalette(c("blue", "white", "red"))(50) cluster_cols"
时间: 2024-04-22 10:24:58 浏览: 26
在的代码中,出现了一个语法错误。在`color`参数时,你使用了``符号,而应该使用等号`=`。
正确的代码应该是:
```R
pheatmap(hmExp,
annotation_col = Type,
color = colorRampPalette(c("blue", "white", "red"))(50),
cluster_cols = F)
```
请注意,等号`=`用于给参数赋值,而不是使用 `<-`。修改后的代码应该能够正常运行。
相关问题
PCA_Plot_3=function (data,Annotation,VAR,Color) { # logcountdata row:genes,column: samples pca <- prcomp(data) pca_out<-as.data.frame(pca$x) df_out<- pca_out %>%tibble::rownames_to_column(var=VAR) %>% left_join(., Annotation) #df_out<- merge (pca_out,Annotation,by.x=0,by.y=0) # label_color<- factor(df_out[,group]) ggplot(df_out,aes_string(x="PC1",y="PC2")) +geom_point(aes_string(colour = Color)) } Deseq2_Deseq_function_2=function (Countdata,Coldata) { dds_fil <- DESeq2:: DESeqDataSetFromMatrix(countData =Countdata, colData = Coldata, design = ~Group) dds_fil_Deg<- DESeq2::DESeq(dds_fil) return(dds_fil_Deg) } pheatmap_singscore=function (pathways,data,Annotation) { Gene_select_anno= data[,colnames(data) %in% pathways] %>%t()%>%.[,rownames(Annotation)] # return(Gene_select_anno) # Anno_expression_data=Gene_select_anno[,c("SYMBOL",Group_select)] %>% as.data.frame() %>% distinct() %>% na.omit() # rownames(Anno_expression_data)=Anno_expression_data[,"SYMBOL"] # Annotation=group_anno["Gene_type"] # input= Anno_expression_data[,Group_select] # F2_pheatmap <- pheatmap::pheatmap(input, cellwigermline calling GATKdth = 10, cellheight = 12, scale = "row", # treeheight_row = 5, # show_rownames = T,show_colnames = T, # annotation_col= Annotation, # # annotation_row=Annotation, # annotation_legend=Label_def, # cluster_rows = T, cluster_cols = F,clustering_distance_rows = "euclidean") pheatmap::pheatmap(Gene_select_anno, cellwigermline=5, cellheight = 10,cellwidth = 10, scale = "row", treeheight_row = 5, show_rownames = T,show_colnames = F, annotation_col= Annotation, # annotation_row=Annotation, #annotation_legend=Label_def, cluster_rows = T, cluster_cols = F,clustering_distance_rows = "euclidean") } matrix.please<-function(x) { m<-as.matrix(x[,-1]) rownames(m)<-x[,1] m } 这是r语言的代码,告诉我每一条代码的作用和意义
PCA_Plot_3: 这个函数用来绘制主成分分析(PCA)的散点图。它接受四个参数:data(数据矩阵),Annotation(注释信息),VAR(行名),Color(颜色)。首先,它对数据进行主成分分析(prcomp函数),然后将主成分分析的结果转换为数据帧(pca_out)。接下来,它将行名转换为指定的VAR变量名,并将注释信息与主成分分析结果进行连接(left_join函数)。最后,它使用ggplot库绘制散点图,其中x轴表示PC1,y轴表示PC2,点的颜色由Color参数指定。
Deseq2_Deseq_function_2: 这个函数用于进行差异表达分析。它接受两个参数:Countdata(基因计数数据)和Coldata(样本注释信息)。首先,它使用DESeq2包中的DESeqDataSetFromMatrix函数将Countdata和Coldata转换为差异表达分析所需的数据集对象。然后,它使用DESeq2包中的DESeq函数进行差异表达分析,并返回结果。
pheatmap_singscore: 这个函数用于绘制热图。它接受三个参数:pathways(基因通路信息),data(基因表达数据),Annotation(注释信息)。首先,它从data中选择pathways对应的基因,并根据Annotation的行名对选定的基因进行筛选。然后,它使用pheatmap包中的pheatmap函数绘制热图,其中Gene_select_anno是待绘制的基因数据,Annotation用于注释列,cluster_rows参数表示是否对行进行聚类,clustering_distance_rows参数表示行聚类所使用的距离度量。
matrix.please: 这个函数用于将数据框转换为矩阵。它接受一个参数x(数据框),并将x的第一列作为行名,将x的其余列转换为矩阵。最后,它返回该矩阵。
请修改以下代码 library(ggplot2) library(gganimate) library(magick) # 读取图片并叠加 imgs <- lapply(1:9, function(i) { img <- image_read(paste0("E:/NorthChinaDustBreakout/z_Figure/FY4/22/", i, ".png")) img }) # 将图片叠加为一张 img <- image_append(imgs, stack = TRUE) # 将图片转换为矩阵 img_matrix <- image_data(img) # 绘制静态图像 p <- ggplot() + annotation_custom(rasterGrob(img_matrix), xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) + theme_void() # 制作动画 anim <- p + transition_time(time) + labs(title = "Frame {frame_time}") + ease_aes('linear') # 导出动画为gif文件 animate(anim, nframes = 100, fps = 10, width = 800, height = 600, renderer = gifski_renderer("E:/NorthChinaDustBreakout/z_Figure/FY4/22/animated_images.gif"))
这段代码的问题在于 `image_data` 函数返回的是一个 Matrix 类型的对象,而 `rasterGrob` 函数需要的是一个 Raster 类型的对象。因此,需要将 Matrix 对象转换为 Raster 对象。
以下是修改后的代码:
```
library(ggplot2)
library(gganimate)
library(magick)
# 读取图片并叠加
imgs <- lapply(1:9, function(i) {
img <- image_read(paste0("E:/NorthChinaDustBreakout/z_Figure/FY4/22/", i, ".png"))
img
})
# 将图片叠加为一张
img <- image_append(imgs, stack = TRUE)
# 将图片转换为矩阵
img_matrix <- image_data(img)
# 将矩阵转换为栅格对象
img_raster <- rasterGrob(img_matrix, interpolate = FALSE)
# 绘制静态图像
p <- ggplot() +
annotation_custom(img_raster, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
theme_void()
# 制作动画
anim <- p +
transition_time(time) +
labs(title = "Frame {frame_time}") +
ease_aes('linear')
# 导出动画为gif文件
animate(anim, nframes = 100, fps = 10, width = 800, height = 600, renderer = gifski_renderer("E:/NorthChinaDustBreakout/z_Figure/FY4/22/animated_images.gif"))
```
在修改后的代码中,我们将 `img_matrix` 从 Matrix 类型转换为 Raster 类型,并将其作为参数传递给 `rasterGrob` 函数。然后,我们将返回的 Raster 对象传递给 `annotation_custom` 函数。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)