,可以通过以下步骤实现:
install.packages("ggplot2")
library(ggplot2)
data <- data.frame(
x = c(group1_x, group2_x, group3_x),
y = c(group1_y, group2_y, group3_y),
group = rep(c("Group 1", "Group 2", "Group 3"), each = length(group1_x))
)
plot <- ggplot(data, aes(x = x, y = y))
plot + geom_point(aes(color = group))
例如,将点的形状设置为圆形,大小设置为3,透明度设置为0.5:
plot + geom_point(aes(color = group), shape = "o", size = 3, alpha = 0.5)
plot + geom_point(aes(color = group), shape = "o", size = 3, alpha = 0.5) +
labs(color = "Group", x = "X", y = "Y", title = "Three Groups of Points") +
theme_minimal()
这样,就可以使用ggplot在同一图上展示三组不同的点了。根据具体需求,可以进一步调整图形的样式和布局。
领取专属 10元无门槛券
手把手带您无忧上云