分类y轴之间蜱我有以下代码:如何减少间隙赌注在GGPLOT2
library(tidyverse)
dat <- structure(list(motif_and_gene_name = c("FCCT", "XXX4", "XXX2",
"FCCT", "XXX4", "XXX2", "FCCT", "XXX4", "XXX2", "FCCT", "XXX4",
"XXX2", "FCCT", "XXX4", "XXX2", "FCCT", "XXX4", "XXX2"), tissue = c("DA",
"DA", "DA", "MB", "MB", "MB", "VL", "VL", "VL", "UP", "UP", "UP",
"BU", "BU", "BU", "TV", "TV", "TV"), motif_enrichment = c(4740,
964.2, 539.2, 6634, 1860, 1150, 6312, 2146, 1432, 5336, 2282,
1381, 2796, 1947, 1175, 8190, 1576, 926.8), expression_tpm = c(5.095,
15.1825, 1.4225, 7.27, 23.7125, 6.85, 4.8775, 27.17, 3.0025,
6.0025, 23.3725, 5.1425, 5.4525, 20.215, 4.695, 6.44, 22.04,
4.24), expr_brks = structure(c(3L, 4L, 2L, 3L, 6L, 3L, 2L, 6L,
2L, 3L, 6L, 3L, 3L, 6L, 2L, 3L, 6L, 2L), .Label = c("(-Inf,1]",
"(1,5]", "(5,10]", "(10,16]", "(16,20]", "(20, Inf]"), class = "factor"),
motif_brks = structure(c(6L, 3L, 3L, 6L, 5L, 4L, 6L, 6L,
4L, 6L, 6L, 4L, 6L, 5L, 4L, 6L, 5L, 3L), .Label = c("(-Inf,100]",
"(100,500]", "(500,1e+03]", "(1e+03,1.5e+03]", "(1.5e+03,2e+03]",
"(2e+03, Inf]"), class = "factor")), .Names = c("motif_and_gene_name",
"tissue", "motif_enrichment", "expression_tpm", "expr_brks",
"motif_brks"), row.names = c(NA, -18L), class = c("tbl_df", "tbl",
"data.frame"))
mycol <- c("#3D1E1F","#FE677E","#F19068","#E8A99D","#FCDED4")
dat %>%
ggplot(aes(x = tissue,y = motif_and_gene_name, size = motif_brks, color = expr_brks)) +
geom_point(stat = "identity") +
scale_color_manual(values = colorRampPalette(mycol)(length(levels(dat$expr_brks)))) +
xlab("") +
ylab("") +
theme_bw()
哪产生以下情节:
作为图像中所述上面,我怎样才能减少蜱间隙 并推动x轴向上。
您可能需要一个'coord_fixed()'行添加到您的代码。更多细节在这里:https://stackoverflow.com/questions/7056836/how-to-fix-the-aspect-ratio-in-ggplot/19207404 –
@ Z.Lin谢谢,但它并没有减少x-轴向FCCT或最高的差距。 – scamander
您可以尝试在'scale_y_discrete()'中设置'expand = c(0,0.3)'。默认扩展值是'c(0,0.6)',所以小于这个值的任何值都会缩小扩展。 –