使用ggplot在同一张图上绘制两组不同配色方案的数据可以通过以下步骤实现:
install.packages("ggplot2")
library(ggplot2)
data1 <- data.frame(x = c(1, 2, 3, 4, 5), y = c(2, 4, 6, 8, 10))
data2 <- data.frame(x = c(1, 2, 3, 4, 5), y = c(1, 3, 5, 7, 9))
plot <- ggplot(data1, aes(x = x, y = y))
plot <- plot + geom_point(color = "blue")
plot <- plot + geom_line(color = "blue")
plot <- plot + geom_point(data = data2, color = "red")
plot <- plot + geom_line(data = data2, color = "red")
plot <- plot + labs(title = "Two Color Schemes", x = "X", y = "Y")
print(plot)
这样就可以在同一张图上绘制两组不同配色方案的数据了。根据具体需求,可以调整颜色、线型、点型等参数来定制图表的样式。
领取专属 10元无门槛券
手把手带您无忧上云