ggpubr
ggpubr copied to clipboard
ggline: Multiple Lines with Common Group Sets
In the following example on ggpubr:
https://rpkgs.datanovia.com/ggpubr/reference/ggline.html
If we have a data frame like this:
df2 <- data.frame(supp=rep(c("VC", "OJ","VC"), each=3), dose=rep(c("D0.5", "D1", "D2"),3), len=c(6.8, 15, 33, 4.2, 10, 29.5, 12, 6, 14.2), num=as.character(rep(c(1:3),each=3)))
How can we make a plot like this but colored based on 'sup'?
ggline(df2, "dose", "len", color="num")
This does not work as it connects the points together!!!
ggline(df2, "dose", "len", color="supp")
The grouping (group = ) solves the problem in ggplot but it does not work in ggpubr.
ggplot(df2, aes(x=dose, y=len, group=num)) + geom_line(aes(linetype=supp,color=supp))+ geom_point(aes(shape=supp))
ggline(df2, "dose", "len", group = "num")
But
ggline(df2, "dose", "len", group = "num", color = "supp")
Error: Aesthetics must be either length 1 or the same as the data (9): group Run
rlang::last_error() to see where the error occurred. In addition: Warning message: In if (is_parsable_aes(x)) { : the condition has length > 1 and only the first element will be used
ggline(df2, "dose", "len", group = "num", color = "num", linetype = "num", size = 2) + scale_color_manual(values = c("black","blue","blue")) + scale_linetype_manual(values = c("solid","dashed","dashed"))
But I still want to color based on "supp" that I would have 2 different groups as legends and not 3 like here!!
Commenting to upvote this issue, facing the same thing at the moment :)