我想构建一个y限制为-3至3的点图。这一次,我的数据不包含-3,因此它没有显示在我的图上。我不想手动将ylim更改为(-3,3)。有办法吗?我尝试了ylim=c(-3,3)
和scale_y_discrete(-3,3)
这是我用来创建点图的ggplot代码,它可以工作,但是y的限制是-2和3。
graf.dot <- ggplot(df.dot,aes(x = data, y = nota, group = data, fill = colour, colour = colour)) + facet_wrap(~taxa) +
geom_dotplot(binaxis = "y", stackdir = "center", dotsize = 2) +
scale_fill_manual(values = c('Negativo' = 'red','Neutro' = 'gray','Positivo'='green','Ref' = 'black')) +
scale_colour_manual(values = c('Negativo' = 'red','Neutro' = 'gray','Positivo'='green','Ref' = 'black')) +
ggtitle("Notas \n") + xlab("") + ylab("") + theme(plot.title = element_text(size = 20, hjust = 0.5),
axis.text.y = element_text(size = 18), axis.text.x = element_text(size = 18),legend.key = element_blank(), legend.title = element_blank(), legend.text = element_text(size = 18), legend.position = "bottom",
strip.text = element_text(size = 18));
和一些样本数据来解决我的问题。
df.dot=structure(list(taxa = c("T1", "T1", "T1", "T1", "T1", "T1", "T1",
"T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1",
"T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1",
"T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2",
"T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2",
"T2", "T2", "T2", "T2", "T2", "T2", "T2", "T3", "T3", "T3", "T3",
"T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3",
"T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3",
"T3", "T3", "T3", "T4", "T4", "T4", "T4", "T4", "T4", "T4", "T4",
"T4", "T4", "T4", "T4", "T4", "T4", "T4", "T4", "T4", "T4", "T4",
"T4", "T4", "T4", "T4", "T4", "T4", "T4", "T4", "T4", "T4", "T5",
"T5", "T5", "T5", "T5", "T5", "T5", "T5", "T5", "T5", "T5", "T5",
"T5", "T5", "T5", "T5", "T5", "T5", "T5", "T5", "T5", "T5", "T5",
"T5", "T5", "T5", "T5", "T5", "T5", "T6", "T6", "T6", "T6", "T6",
"T6", "T6", "T6", "T6", "T6", "T6", "T6", "T6", "T6", "T6", "T6",
"T6", "T6", "T6", "T6", "T6", "T6", "T6", "T6", "T6", "T6", "T6",
"T6", "T6", "T7", "T7", "T7", "T7", "T7", "T7", "T7", "T7", "T7",
"T7", "T7", "T7", "T7", "T7", "T7", "T7", "T7", "T7", "T7", "T7",
"T7", "T7", "T7", "T7", "T7", "T7", "T7", "T7", "T7"), data = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,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 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Negativo",
"Neutro", "Positivo", "Ref"), class = "factor")), row.names = c(NA,
-203L), class = "data.frame")
1条答案
按热度按时间qjp7pelc1#
应该将
breaks
和limits
添加到scale_y_discrete
,如下所示:创建于2023年1月4日,使用reprex v2.0.2