title: “LABS44_A”
author: “JESSICA PAOLA AGUILAR SERVIN”
date: “2023-03-09”
output: html_document

LABORATORIO

ADICIONALES library(dplyr) library(seurat) library(patchwork) library(ggplot2) library(complexheatmap) library(seuratdata) library(hdWGCNA) library(WGCNA)

install.packages(gplots) library (gplot)

CARGAR LIBRERIA NECESARIA

library(stats)

PAQUETES DE GPLOTS. Attaching package: ‘gplots’.lowess ANEXAMOS DATOS

h1 <- c(10,20,10,20,10,20,10,20)
h2 <- c(20,10,20,10,20,10,20,10)

l1 <- c(1,3,1,3,1,3,1,3)
l2 <- c(3,1,3,1,3,1,3,1)

mat <- rbind(h1,h2,l1,l2)

CREAR GRÁFICO

par(mfrow =c(1,1), mar=c(4,4,1,1))
plot(1:8,rep(0,8), ylim=c(0,35), pch="", xlab="Time", ylab="Gene Expression")

for (i in 1:nrow(mat)) {lines(1:8,mat[i,], lwd=3, col=i)}
legend(1,35,rownames(mat), 1:4, cex=0.7)

CALCULAR DISTANCIA

dist(mat)
##           h1        h2        l1
## h2 28.284271                    
## l1 38.470768 40.496913          
## l2 40.496913 38.470768  5.656854

SACAR PLOT-use the default for linkage method: complete

plot(hclust(dist(mat)))

CALCULAR HEATMAP DE RENGLONES heatmap (mat, Colv=NA, col= greenred(10), scale = “row”) heatmap (mat, Colv=NA, col=greenred(10), scale = “none”)

mat.scaled<- t(scale(t(mat), center=TRUE, scale = TRUE))
mat.scaled
##          [,1]       [,2]       [,3]       [,4]       [,5]       [,6]       [,7]
## h1 -0.9354143  0.9354143 -0.9354143  0.9354143 -0.9354143  0.9354143 -0.9354143
## h2  0.9354143 -0.9354143  0.9354143 -0.9354143  0.9354143 -0.9354143  0.9354143
## l1 -0.9354143  0.9354143 -0.9354143  0.9354143 -0.9354143  0.9354143 -0.9354143
## l2  0.9354143 -0.9354143  0.9354143 -0.9354143  0.9354143 -0.9354143  0.9354143
##          [,8]
## h1  0.9354143
## h2 -0.9354143
## l1  0.9354143
## l2 -0.9354143
## attr(,"scaled:center")
## h1 h2 l1 l2 
## 15 15  2  2 
## attr(,"scaled:scale")
##       h1       h2       l1       l2 
## 5.345225 5.345225 1.069045 1.069045

DISTANCIA ENTRE GENES

dist(mat.scaled)
##          h1       h2       l1
## h2 5.291503                  
## l1 0.000000 5.291503         
## l2 5.291503 0.000000 5.291503

NUEVO GRAFICO

plot(hclust(dist(mat.scaled)))

heatmap(mat.scaled, Colv = NA, scale = “none”)

CORRELACION ENTRE GENES

cor(t(mat))
##    h1 h2 l1 l2
## h1  1 -1  1 -1
## h2 -1  1 -1  1
## l1  1 -1  1 -1
## l2 -1  1 -1  1

DISTANCIA EN LAS CORRELACIONES

1- cor(t(mat))
##    h1 h2 l1 l2
## h1  0  2  0  2
## h2  2  0  2  0
## l1  0  2  0  2
## l2  2  0  2  0

GRAFICAS

hc <- hclust(as.dist(1-cor(t(mat))))
plot(hc)

PRIMERA ADECUACION HEATMAPS

heatmap(mat, Colv = NA, Rowv=as.dendrogram(hc), scale = "none")

SEGUNDA oPCION DE HEATMAPS

heatmap(mat, trace = "none", Colv= NA, dendrogram = "row", scale = "none")
## Warning in plot.window(...): "trace" is not a graphical parameter
## Warning in plot.window(...): "dendrogram" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "trace" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "dendrogram" is not a graphical parameter
## Warning in title(...): "trace" is not a graphical parameter
## Warning in title(...): "dendrogram" is not a graphical parameter

TERCERA OPCION HEATMAPS

heatmap(mat, trace = "none", Colv= NA, dendrogram = "row", scale = "row")
## Warning in plot.window(...): "trace" is not a graphical parameter
## Warning in plot.window(...): "dendrogram" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "trace" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "dendrogram" is not a graphical parameter
## Warning in title(...): "trace" is not a graphical parameter
## Warning in title(...): "dendrogram" is not a graphical parameter

CUARTA OPCION HEATMAPS USANDO DISTANCIA ECLUDIANA

heatmap (t(scale(t(mat), center=TRUE, scale=TRUE)), trace = "none", Colv= NA, dendrogram = "row")
## Warning in plot.window(...): "trace" is not a graphical parameter
## Warning in plot.window(...): "dendrogram" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "trace" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "dendrogram" is not a graphical parameter
## Warning in title(...): "trace" is not a graphical parameter
## Warning in title(...): "dendrogram" is not a graphical parameter

USO 1-COR (x) DE CORRELACION EN HEAT

heatmap (mat, trace = "none", 
  Colv= NA, dendrogram = "row",
  scale = "none",
  hclust=function(x) hclust(x, method="complete"), distfun=function(x) as.dist(1-cor(t(x))))
## Warning in plot.window(...): "trace" is not a graphical parameter
## Warning in plot.window(...): "dendrogram" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "trace" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "dendrogram" is not a graphical parameter
## Warning in title(...): "trace" is not a graphical parameter
## Warning in title(...): "dendrogram" is not a graphical parameter

OTRA ESCALA REPRESENTADA POR LOS COLORES

heatmap(mat, trace = "none", 
          Colv= NA, dendrogram = "row",
          scale = "row",
          hclust=function(x) hclust(x, method='complete'), distfun=function(x) as.dist(1-cor(t(x))))
## Warning in plot.window(...): "trace" is not a graphical parameter
## Warning in plot.window(...): "dendrogram" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "trace" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "dendrogram" is not a graphical parameter
## Warning in title(...): "trace" is not a graphical parameter
## Warning in title(...): "dendrogram" is not a graphical parameter

ULTIMA COLORACION DE CLUSTERS

heatmap(t(scale(t(mat), center=TRUE, scale=TRUE)), trace = "none", 
Colv= NA, dendrogram = "row",
hclust=function(x) hclust(x, method='complete'), distfun=function(x) as.dist(1-cor(t(x))))
## Warning in plot.window(...): "trace" is not a graphical parameter
## Warning in plot.window(...): "dendrogram" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "trace" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "dendrogram" is not a graphical parameter
## Warning in title(...): "trace" is not a graphical parameter
## Warning in title(...): "dendrogram" is not a graphical parameter