r - ggplot2 geom_line() should point at specified value -


i have written following code:

library(ggplot2)  data <- structure(list(x = c(1l, 6l, 3l, 4l, 2l, 3l, 6l, 1l, 5l, 2l,                      1l, 5l), y = c(1l, 7l, 5l, 6l, 3l, 4l, 6l, 2l, 5l, 6l, 5l, 2l             ), year = structure(c(1l, 1l, 1l, 1l, 1l, 1l, 2l, 2l, 2l, 2l,                              2l, 2l), .label = c("2010", "2011"), class = "factor"), matching = structure(c(1l,                              2l, 3l, 4l, 5l, 6l, 1l, 2l, 3l, 4l, 5l, 6l), .label = c("person1",                              "person2", "person3", "person4", "person5", "person6"), class = "factor")), .names = c("x",              "y", "year", "matching"), row.names = c(na, -12l), class = "data.frame")  data$year <- factor(data$year)  colors <- c("#4cb5ee", "#a0d099", "red")  p <- ggplot(data, aes(x=x, y=y)) +     geom_point(aes(colour=year), shape=16, size=6) +     geom_line(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) 

it gives following output: plot

but want geom_line() is: points @ point year=2011. can't figure out why arrow of line point @ point refers year=2010 , points @ point year=2011.

what found out arrow takes several arguments:

arrow(angle = 30, length = unit(0.25, "inches"), ends = "last", type = "open")  

so ends="first". can't generalize ends first or last.

i tried add column data.frame has information if arrow should end first or last, didn't gives me output wanted.

every highly appreciated :-)

thanks in advance!

geom_path should 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


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -