Here is a simple ggplot chart for two variables:
library("ggplot2")
library("directlabels")
library("tibble")
df <- tibble(
number = 1:10,
var1 = runif(10)*10,
var2 = runif(10)*10
)
ggplot(df, aes(number))+
geom_line(aes(y=var1), color='red')+
geom_line(aes(y=var2), color='blue')
Is it possible to label the last value of var1 and var2 using the expression like that:
direct.label(df, 'last.points')
In my case I get an error:
Error in UseMethod("direct.label") :
no applicable method for 'direct.label' applied to an object of
class
Maria, you initially need to structure your data frame by "stacking data". I like to use the
meltfunction of thereshape2package. This will allow you to use only onegeom_line.Later you need to generate an object from
ggplot2. And this object you must apply thedirectlabelspackage.