Reputation: 413
I have a matrix like this:
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
I am trying to make a graph with ggplot2
, but I would like to represent one group with a line and the other group with points. How could I do that?
Upvotes: 3
Views: 2021
Reputation: 5314
you can try this
ggplot(df, aes(x, y))+
geom_point(data=df[df$group==2, ])+
geom_line(data=df[df$group==1, ])
data
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"))
Upvotes: 2