ggpubr icon indicating copy to clipboard operation
ggpubr copied to clipboard

ggline: Multiple Lines with Common Group Sets

Open AlirezaTafazzol opened this issue 3 years ago • 4 comments

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)))

image

How can we make a plot like this but colored based on 'sup'? ggline(df2, "dose", "len", color="num") image

This does not work as it connects the points together!!! ggline(df2, "dose", "len", color="supp") image

AlirezaTafazzol avatar Feb 05 '21 22:02 AlirezaTafazzol

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))

image

AlirezaTafazzol avatar Feb 05 '21 23:02 AlirezaTafazzol

ggline(df2, "dose", "len", group = "num") image

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

AlirezaTafazzol avatar Feb 05 '21 23:02 AlirezaTafazzol

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"))

image

But I still want to color based on "supp" that I would have 2 different groups as legends and not 3 like here!!

AlirezaTafazzol avatar Feb 05 '21 23:02 AlirezaTafazzol

Commenting to upvote this issue, facing the same thing at the moment :)

FriederikeHanssen avatar Feb 21 '23 12:02 FriederikeHanssen