geom_dotplot点位置不对称偏离X轴刻度问题求助
geom_dotplot点偏离X轴刻度中心问题求助
刚解决了geom_dotplot的一个问题,现在遇到新问题:部分分类(ID的levels)的点偏离X轴刻度标记中心,虽非大问题,但使图表显得杂乱。以下是我的数据、代码及图表截图:
我的数据
structure(list(ID = structure(c(14L, 16L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 10L, 10L, 13L, 14L, 15L, 16L, 16L, 19L), levels = c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T" ), class = "factor"), value = c(2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2, 2.5, 2, 2.5, 1, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5)), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), row.names = c(NA, -24L), groups = structure(list( ID = structure(c(2L, 3L, 6L, 7L, 10L, 13L, 14L, 15L, 16L, 19L), levels = c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T" ), class = "factor"), .rows = structure(list(3:5, 6:9, 10:15, 16L, 17:18, 19L, c(1L, 20L), 21L, c(2L, 22L, 23L), 24L), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame" ), row.names = c(NA, -10L), .drop = TRUE))
我的代码
ggplot(data, aes(x = ID, fill=as.factor(value))) + geom_dotplot(dotsize = 1, stackratio = 1.2, method = "histodot", stackgroups = TRUE) + labs(title = "title", x = "", y = "", fill = "value") + theme_bw() + scale_y_continuous(NULL, breaks = NULL) + scale_x_discrete(drop = FALSE) + theme(plot.title = element_text(size= 13), axis.text.x = element_text(size = 10), plot.margin = unit(c(0, 0.2, 0, 0.2), "inches"))
图表截图

内容的提问来源于stack exchange,提问作者zooxanthellae
相关产品推荐
相关产品推荐

