r Error: Don't know how to add o to a plot

17,860

Do this instead

 library(grid)
library(ggplot2)
df <- data.frame(x=(1:2),y=(2:1))
ggplot(df,aes(x,y)) +
 geom_line(arrow = arrow(length=unit(0.30,"cm"), ends="first", type ="closed"))
Share:
17,860
SteveM49
Author by

SteveM49

Updated on June 23, 2022

Comments

  • SteveM49
    SteveM49 almost 2 years

    I am trying to add arrow heads to a line created by geom_line() in ggplot. Example:

    library(grid)
    library(ggplot2)
    df <- data.frame(x=(1:2),y=(2:1))
    ggplot(df,aes(x,y)) +
        geom_line() +
        arrow()
    

    The error I get is "Error: Don't know how to add o to a plot".
    I found a variety of posts with this error, but they had a complex scenario and the answers called for making what looked like subtle changes in the code.

    If instead I run:

    ggplot(data=cinterval,aes(x=x,y=y))+
        geom_line()
    

    I get the expected line. When I run the expanded code, with a more elaborate plot, I get the error "Error in as.vector(y) : attempt to apply non-function"