我有一个像这样的矩阵:
names x y group
1 1 -0.050 -0.76 2
2 2 0.040 -0.36 2
3 3 0.060 -0.28 2
4 4 0.080 -0.22 1
5 5 0.080 -0.14 1
6 6 0.040 -0.26 1
7 7 0.030 -0.36 1
我正在尝试使用ggplot2
制作图表,但我想用一条线代表一个组,而另一组用点代表。我怎么能这样做?
答案 0 :(得分:2)
你可以试试这个
ggplot(df, aes(x, y))+
geom_point(data=df[df$group==2, ])+
geom_line(data=df[df$group==1, ])
数据
df <- dput(df)
structure(list(names = 1:7, x = c(-0.05, 0.04, 0.06, 0.08, 0.08,
0.04, 0.03), y = c(-0.76, -0.36, -0.28, -0.22, -0.14, -0.26,
-0.36), group = c(2L, 2L, 2L, 1L, 1L, 1L, 1L)), .Names = c("names",
"x", "y", "group"), class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6", "7"))