ggplot2 geom_line() should point at specified value

前端 未结 2 1258
攒了一身酷
攒了一身酷 2021-02-10 08:53

I have written the following code:

library(ggplot2)

data <- structure(list(x = c(1L, 6L, 3L, 4L, 2L, 3L, 6L, 1L, 5L, 2L, 
                    1L, 5L), y = c(         


        
2条回答
  •  醉话见心
    2021-02-10 09:16

    geom_path should do the trick:

    p <- ggplot(data, aes(x=x, y=y)) +
        geom_point(aes(colour=year), shape=16, size=6) +
        geom_path(aes(group=matching), 
                      arrow=arrow(length=unit(0.15,"cm")),
                      colour="black", size=1) +
        xlab("x") + ylab("y") +
        scale_colour_manual("year", values=colors) +
        scale_x_continuous(limits=c(1,7), breaks=seq(1,7, by=1)) +
        scale_y_continuous(limits=c(1,7), breaks=seq(1,7, by=1))
    
    print(p)
    

    geom_path plot

提交回复
热议问题