[R] add segments from other data ggplot
R.E.Crump at warwick.ac.uk
Mon Aug 15 12:56:43 CEST 2016
In your code:
p<-ggplot(ram.ag, aes(Raman, XRD, colour=mereni))
yend=XRDnov), arrow = arrow(length = unit(1,"cm")))
you have set mereni to control the colour aesthetic in the call to ggplot.
This will be used in all subsequent calls to geoms, unless you make a
local call to aes to override it. So both ram.ag and dat would require
mereni columns for this to work.
In the second piece of code you use a call to aes to override colour in
the call to geom_segment, which gets you past the error, but do not set it
to a variable in dat. You shouldn't set an aesthetic to a constant
("black"), use colour="black" outside of the aes() if you want it set
(although it is redundant in this case, black being the default).
If you are using multiple data sources it is probably safer to refer to
them and set the appropriate aesthetics where they are used, e.g.
p <- ggplot()+geom_point(data=ram.ag,aes(x=Raman,y=XRD,colour=mereni))+
Hope this helps, I apologise if it isn't very clear.
More information about the R-help