我在 R 中使用 ggplot2 使用 facet_wrap() 来可视化数据,我想调整图形的大小,以便行数较多的图形(示例中的 MF 和 CC)显得更大,而行数较少的图形( BP)较小。但整个图表的大小并没有改变。这是数据示例:
df <- data.frame(
'Seq ratio' = runif(15, min = 0, max = 0.5),
'feature' = stringi::stri_rand_strings(15, 1, pattern = "[A-F]"),
'Seq count' = c(8, 10, 8, 8, 8, 4, 4, 4, 5, 4, 4, 7, 15, 15, 15),
'adj. P value' = c(0.012609566, 0.012609566, 0.033278332, 0.021875357,
0.021875357,0.003216359, 0.003216359, 0.003216359, 0.030076544, 0.017188404,
0.003216359, 0.047018661, 0.002584020, 0.002584020, 0.002584020),
'cluster' = c('Cluster 1', 'Cluster 1', 'Cluster 1', 'Cluster 1',
'Cluster 1', 'Cluster 2', 'Cluster 2', 'Cluster 2', 'Cluster 2',
'Cluster 3', 'Cluster 3', 'Cluster 4', 'Cluster 4', 'Cluster 4', 'Cluster 4'),
'Category' = c('MF', 'MF', 'CC', 'MF', 'CC', 'BP', 'BP', 'BP',
'BP', 'MF', 'MF', 'BP', 'CC', 'CC', 'CC'))
ggplot(aes(seq_ratio, feature, size = seq_count, colour = adj_p_value)) +
facet_wrap(~category, ncol = 1, scales = "free_y") +
geom_point() +
ylab(NULL) +
scale_x_continuous(n.breaks = 5) +
scale_size(name = "Seq count", limits = c(0, 15))