[R] Using ggplot2 geom_path() in a grouped variable

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Tue Feb 12 23:22:38 CET 2019


I am not understanding the problem.
With a made up dataset everything seems right.

set.seed(1234)    # make the results reproducible
n <- 10
data <- data.frame(Pretrend = rep(1:10, 2),
                    Outcome = 1:10 + rnorm(2*n),
                    Control = rep(1:2, each = n))


p <- ggplot(data, aes(Pretrend, Outcome, colour = factor(Control))) +
   geom_point() +
   geom_path() +
   labs(x = "Date", y = "Cases", title = "Intoxication Cases")


I have changed the plot name because 'plot' is the name of a base R 

What is the problem with the graph above? Is that what you were looking 
for? (Or similar.)

Hope this helps,

Rui Barradas

Às 20:09 de 12/02/2019, Norberto Hernandez escreveu:
> Hi! I am trying to make a scatter/path graph in one variable that is
> divided in two groups (variable Control), but when I use the
> geom_path() option, the line continues from the group one to the group
> two, and I wasn't able to avoid it.I need the path draws over the
> group one and then draws over the group two avoiding the connection
> between the last value of group one and the first value of group two.
> This is my code
> library(ggplot2)
> plot <- ggplot(data, aes(Pretrend, Outcome)) + geom_point()
> plot + geom_point(aes(colour=factor(Control)))+labs(x="Date",
> y="Cases", title="Intoxication Cases")+geom_path()
> Could you please bring be some advice.
> Regards
> Norberto Francisco Hernández
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list