@@ -63,13 +63,23 @@ spe$k18.f = factor(spe$PRECAST_k18, levels=c(10,8,1,
6363
6464
6565
66- plotGroupedHeatmap(spe , features = genes , group = " k16.f" , swap_rownames = " gene_name" ,
66+ hm1 = plotGroupedHeatmap(spe , features = genes , group = " k16.f" , swap_rownames = " gene_name" ,
6767 center = T , scale = T , zlim = c(- 2 ,4 ),
6868 cluster_rows = F , cluster_cols = F , border_col = " white" ,
6969 color = RColorBrewer :: brewer.pal(9 ," Greys" ),
70- angle_col = " 0" )
71-
72-
70+ angle_col = " 0" , fontsize = 10 , fontsize_row = 12 , silent = T )
71+ hm2 = plotGroupedHeatmap(spe , features = genes , group = " k17.f" , swap_rownames = " gene_name" ,
72+ center = T , scale = T , zlim = c(- 2 ,4 ),
73+ cluster_rows = F , cluster_cols = F , border_col = " white" ,
74+ color = RColorBrewer :: brewer.pal(9 ," Greys" ),
75+ angle_col = " 0" , fontsize = 10 , fontsize_row = 12 , silent = T )
76+ hm3 = plotGroupedHeatmap(spe , features = genes , group = " k18.f" , swap_rownames = " gene_name" ,
77+ center = T , scale = T , zlim = c(- 2 ,4 ),
78+ cluster_rows = F , cluster_cols = F , border_col = " white" ,
79+ color = RColorBrewer :: brewer.pal(9 ," Greys" ),
80+ angle_col = " 0" , fontsize = 10 , fontsize_row = 12 , silent = T )
81+ ggsave(file = " plots/revision/supp_PRECAST-compare-k_heatmap.pdf" , gridExtra :: grid.arrange(hm1 [[4 ]], hm2 [[4 ]], hm3 [[4 ]], ncol = 3 ),
82+ height = 4 , width = 12 , units = " in" )
7383
7484# ############### make pies
7585# for pies need manual annotation
@@ -106,32 +116,52 @@ man.pal = c("THAL"="#1e1eff","CTX"="#5ffffb", "SUB"="#add294", "PCL-CA1"="#00dc0
106116 " GCL" = " #005000" , " SGZ" = " #dfa56e" , " ML" = " #c1c1c1" , " SL" = " #444444" , " SR" = " #828E84" , " SLM" = " tan4" ,
107117 " SO" = " #A698AE" , " WM" = " #ff3ffc" , " CP" = " #00006a" )
108118
109- ggplot(as.data.frame(colData(spe.manual )), aes(x = " " , fill = ManualAnnotation ))+
110- geom_bar(stat = " count" , position = " fill" )+
119+ p1 <- ggplot(as.data.frame(colData(spe.manual )), aes(x = " " , fill = ManualAnnotation ))+
120+ geom_bar(stat = " count" , position = " fill" , color = " white" , linewidth = .3 )+
121+ scale_fill_manual(values = man.pal )+
122+ facet_wrap(vars(k16.f ), ncol = 5 )+ theme_void()+
123+ coord_polar(theta = " y" )+ labs(title = " PRECAST k=16 clusters" )+
124+ theme(aspect.ratio = 1 , legend.position = " none" , strip.text = element_text(size = 12 ))
125+ p2 <- ggplot(as.data.frame(colData(spe.manual )), aes(x = " " , fill = ManualAnnotation ))+
126+ geom_bar(stat = " count" , position = " fill" , color = " white" , linewidth = .3 )+
127+ scale_fill_manual(values = man.pal )+
128+ facet_wrap(vars(k17.f ), ncol = 5 )+ theme_void()+
129+ coord_polar(theta = " y" )+ labs(title = " PRECAST k=17 clusters" )+
130+ theme(aspect.ratio = 1 , legend.position = " none" , strip.text = element_text(size = 12 ))
131+ p3 <- ggplot(as.data.frame(colData(spe.manual )), aes(x = " " , fill = ManualAnnotation ))+
132+ geom_bar(stat = " count" , position = " fill" , color = " white" , linewidth = .3 )+
111133 scale_fill_manual(values = man.pal )+
112134 facet_wrap(vars(k18.f ), ncol = 5 )+ theme_void()+
113135 coord_polar(theta = " y" )+ labs(title = " PRECAST k=18 cluster" )+
114- theme(aspect.ratio = .8 , legend.position = " none" )
136+ theme(aspect.ratio = 1 , legend.position = " none" , strip.text = element_text(size = 12 ))
137+
138+ pdf(file = " plots/revision/supp_PRECAST-compare-k_pie.pdf" , height = 4 , width = 12 )
139+ gridExtra :: grid.arrange(p1 + theme(panel.spacing = unit(6 , " pt" ), plot.margin = unit(c(6 ,12 ,6 ,12 )," pt" )),
140+ p2 + theme(panel.spacing = unit(6 , " pt" ), plot.margin = unit(c(6 ,12 ,6 ,12 )," pt" )),
141+ p3 + theme(panel.spacing = unit(6 , " pt" ), plot.margin = unit(c(6 ,12 ,6 ,12 )," pt" )), ncol = 3 )
142+ dev.off()
115143
116144# legend for pies
117- ggplot(cbind.data.frame(" y" = c(rep(1 ,4 ), rep(2 ,3 ), rep(3 ,6 ), rep(4 ,2 )),
145+ pl <- ggplot(cbind.data.frame(" y" = c(rep(1 ,4 ), rep(2 ,3 ), rep(3 ,6 ), rep(4 ,2 )),
118146 " x" = c(seq(from = 1 , by = .2 , length.out = 4 ),
119- seq(from = 1 , by = .2 , length.out = 3 ),
120- seq(from = 1 , by = .2 , length.out = 6 ),
147+ # seq(from=1, by=.2, length.out=3),
148+ c(1.4 ,1.0 ,1.2 ),# swap PCL-CA3 to end
149+ seq(from = 1 , by = .2 , length.out = 6 ),
121150 seq(from = 1 , by = .2 , length.out = 2 )),
122151 " labels" = names(man.pal )),
123152 aes(x = x , y = y , color = factor (labels , levels = names(man.pal ))))+
124- geom_point(size = 3 )+ scale_color_manual(values = man.pal )+
125- geom_text(aes(label = labels ), nudge_x = .03 , hjust = 0 , color = " black" , size = 4 )+
153+ geom_point(size = 2 )+ scale_color_manual(values = man.pal )+
154+ geom_text(aes(label = labels ), nudge_x = .03 , hjust = 0 , color = " black" , size = 3 )+
126155 scale_y_reverse()+ scale_x_continuous(expand = expansion(add = c(.1 ,.2 )))+
127156 theme_void()+
128157 theme(legend.position = " none" ,
129- plot.margin = unit(c(1 ,.2 ,1 ,.2 )," cm" ))
158+ plot.margin = unit(c(.2 ,.2 ,.2 ,.2 )," cm" ))
130159
160+ ggsave(" plots/revision/supp_PRECAST-compare-k_pie-legend.pdf" , pl , height = 1 , width = 3 )
131161
132162# ############### spot plots
133163
134- test = spe [,spe $ sample_id %in% c( " Br3942_V11L05-333_C1 " , " Br3942_V11L05- 333_D1" ) ]
164+ test = spe [,spe $ sample_id == " Br3942_V11L05-333_D1" ]
135165load(file = here :: here(' plots' ,' spatial_palette_final.rda' ))
136166
137167k16.pal = c(" 10" = " #5ffffb" ," 8" = " #99ff99" ," 1" = " #61963d" , " 14" = " #add294" , " 9" = " #00dc00" ,
@@ -144,50 +174,33 @@ k17.k18.pal = c("10"="#5ffffb","8"="#99ff99","1"="#61963d", "14"="#add294", "9"=
144174 " 13" = " #444444" , " 5" = " #777777" , " 15" = " #dfa56e" ,
145175 " 6" = " #ff3ffc" , " 16" = " #7a007a" , " 18" = " #ff80fe" , " 12" = " #00006a" , " 11" = " #1e1eff" )
146176
147- # test$is15_k17 = test$PRECAST_k17==15
148- # test$is15_k18 = test$PRECAST_k18==15
149- plotSpots(test , annotate = " k16.f" , sample_id = " sample_id" ,
177+ p1 <- plotSpots(test , annotate = " k16.f" , sample_id = " sample_id" ,
150178 point_size = .5 )+
151- scale_color_manual(values = k16.pal )+ theme_void()+ ggtitle(" k=16" )
152-
153- # legend
154- ggplot(cbind.data.frame(" y" = c(1 : 9 , 1 : 7 ), " x" = c(rep(1 ,9 ), rep(1.25 ,7 )),
155- " labels" = names(k16.pal )),
156- aes(x = x , y = y , color = factor (labels , levels = names(k16.pal ))))+
157- geom_point(size = 3 )+ scale_color_manual(values = k16.pal )+
158- geom_text(aes(label = labels ), nudge_x = .06 , hjust = 0 , color = " black" , size = 4 )+
159- scale_y_reverse()+ scale_x_continuous(expand = expansion(add = c(.1 ,.4 )))+ # theme_bw()+
160- theme_void()+
161- theme(legend.position = " none" ,
162- plot.margin = unit(c(1 ,.2 ,1 ,.2 )," cm" ))
163-
164- plotSpots(test , annotate = " k17.f" , sample_id = " sample_id" ,
165- point_size = .5 )+
166- scale_color_manual(values = k17.k18.pal )+ theme_void()+ ggtitle(" k=17" )
167-
168- # legend
169- ggplot(cbind.data.frame(" y" = c(1 : 9 , 1 : 8 ), " x" = c(rep(1 ,9 ), rep(1.25 ,8 )),
170- " labels" = setdiff(names(k17.k18.pal )," 18" )),
171- aes(x = x , y = y , color = factor (labels ,
172- levels = setdiff(names(k17.k18.pal )," 18" ))))+
173- geom_point(size = 3 )+ scale_color_manual(values = k17.k18.pal )+
174- geom_text(aes(label = labels ), nudge_x = .06 , hjust = 0 , color = " black" , size = 4 )+
175- scale_y_reverse()+ scale_x_continuous(expand = expansion(add = c(.1 ,.4 )))+ # theme_bw()+
176- theme_void()+
177- theme(legend.position = " none" ,
178- plot.margin = unit(c(1 ,.2 ,1 ,.2 )," cm" ))
179-
180- plotSpots(test , annotate = " k18.f" , sample_id = " sample_id" ,
181- point_size = .5 )+
182- scale_color_manual(values = k17.k18.pal )+ theme_void()+ ggtitle(" k=18" )
183-
184- # legend
185- ggplot(cbind.data.frame(" y" = c(1 : 9 , 1 : 9 ), " x" = c(rep(1 ,9 ), rep(1.25 ,9 )),
186- " labels" = names(k17.k18.pal )),
187- aes(x = x , y = y , color = factor (labels , levels = names(k17.k18.pal ))))+
188- geom_point(size = 3 )+ scale_color_manual(values = k17.k18.pal )+
189- geom_text(aes(label = labels ), nudge_x = .06 , hjust = 0 , color = " black" , size = 4 )+
190- scale_y_reverse()+ scale_x_continuous(expand = expansion(add = c(.1 ,.4 )))+ # theme_bw()+
191- theme_void()+
192- theme(legend.position = " none" ,
193- plot.margin = unit(c(1 ,.2 ,1 ,.2 )," cm" ))
179+ scale_color_manual(values = k16.pal )+
180+ guides(colour = guide_legend(ncol = 2 ))+
181+ theme_void()+ labs(color = " k=16" )+
182+ theme(strip.text = element_blank(), legend.key.size = unit(12 , " pt" ),
183+ legend.title = element_text(size = 12 ), legend.text = element_text(size = 10 ),
184+ legend.box.spacing = unit(0 , " pt" ), legend.margin = margin(0 ,2 ,0 ,0 , " pt" ))
185+
186+ p2 <- plotSpots(test , annotate = " k17.f" , sample_id = " sample_id" ,
187+ point_size = .5 )+
188+ scale_color_manual(values = k17.k18.pal )+
189+ guides(colour = guide_legend(ncol = 2 ))+
190+ theme_void()+ labs(color = " k=17" )+
191+ theme(strip.text = element_blank(), legend.key.size = unit(12 , " pt" ),
192+ legend.title = element_text(size = 12 ), legend.text = element_text(size = 10 ),
193+ legend.box.spacing = unit(0 , " pt" ), legend.margin = margin(0 ,2 ,0 ,0 , " pt" ))
194+
195+ p3 <- plotSpots(test , annotate = " k18.f" , sample_id = " sample_id" ,
196+ point_size = .5 )+
197+ scale_color_manual(values = k17.k18.pal )+
198+ guides(colour = guide_legend(ncol = 2 ))+
199+ theme_void()+ labs(color = " k=18" )+
200+ theme(strip.text = element_blank(), legend.key.size = unit(12 , " pt" ),
201+ legend.title = element_text(size = 12 ), legend.text = element_text(size = 10 ),
202+ legend.box.spacing = unit(0 , " pt" ), legend.margin = margin(0 ,2 ,0 ,0 , " pt" ))
203+
204+ pdf(file = " plots/revision/supp_PRECAST-compare-k_spot-plots.pdf" , height = 4 , width = 12 )
205+ gridExtra :: grid.arrange(p1 , p2 , p3 , ncol = 3 )
206+ dev.off()
0 commit comments