你可以使用position = position_jitter():
ggplot(df, aes(x = POS_start, y = as.factor(Set), color = as.factor(Type))) +
geom_point(position = position_jitter(height = 0.2), show.legend = FALSE) +
theme_classic() +
scale_color_manual(values = colorRampPalette(c("pink", "purple"))(5)) +
labs(x = "CDS Position", y = "Dataset")
编辑:
OP说他们需要能够做其他事情,所以另一种方法是用scale_y_continuous手动控制y轴:
df$Dataset_jit <- jitter(as.numeric(factor(df$Set)))
ggplot(df, aes(x = POS_start, y = Dataset_jit, color = as.factor(Type))) +
geom_point(show.legend = FALSE) +
theme_classic() +
scale_color_manual(values = colorRampPalette(c("pink", "purple"))(5)) +
scale_y_continuous(breaks = 1:3, labels = c("Data 1", "Data 2", "Data 3")) +
labs(x = "CDS Position", y = "Dataset")
样本数据
set.seed(3)
df <- data.frame(POS_start = round(runif(n = 100,1,1500),0),
Set = sample(1:3,100, prob = c(0.45,0.1,0.45), replace = TRUE),
Type = sample(1:5,100,replace = TRUE))