Is it possible to include group = variable and add another point in ggplot.
d <- data.frame(Cement)
dd <- melt(d,id.var = "y")
d2 <- runif(length(dd[,1]))
d2 <- data.frame(first = dd$y,
second = d2)
ggplot(dd, aes(x = y,y = value,group = variable)) +
geom_point(data = d2,aes(x = first,y = second))
This leads to an error. Eventually I would like to add the points specified here onto the line plot.
Best How To :
Mapped aesthetics in ggplot2 follow a sort of inheritance pattern. When you map aesthetics at the "top" level, in
ggplot(), they are automatically passed down to all subsequent layers.
This means that
geom_point is looking for a
variable column in
d2. It won't look for
value columns, since you explicitly re-mapped the x and y aesthetics in
The solution is either to move the top level aesthetic mappings from
geom_line(), or to un-map
group = NULL.
Additionally, Didzis pointed out a third solution in the comments, which is to add
inherit.aes = FALSE to