In the attached example figure, the values from condition one to condition two either increased or decreased. How to show in different line style and color for those which increased or decreased. ![paired_boxplot][1] [1]: https://ibb.co/nBo827
In the attached example figure, the values from condition one to condition two either increased or decreased. How to show in different line style and color for those which increased or decreased. ![paired_boxplot][1] [1]: https://ibb.co/nBo827
Can I suggest you dump ggpaired and do it in ggplot2 (I can't quite understand why ggpaired wasn't written as a geom_* function).
I can't quite divine how your data is structured (is Time a duplication of Condition and if so, why?) so I'm going to assume it looks like this:
library(tidyverse)
library(magrittr)
set.seed(1)
my_data <- data.frame(
Accuracy = rnorm(10),
Condition = rep(c("condition1", "condition2"), each = 5),
Patient = rep(paste0("P", 1:5), times = 2)
)
> my_data
Accuracy Condition Patient
1 -0.6264538 condition1 P1
2 0.1836433 condition1 P2
3 -0.8356286 condition1 P3
4 1.5952808 condition1 P4
5 0.3295078 condition1 P5
6 -0.8204684 condition2 P1
7 0.4874291 condition2 P2
8 0.7383247 condition2 P3
9 0.5757814 condition2 P4
10 -0.3053884 condition2 P5
In ggplot2 you've got more control:
# lines all the same colour
ggplot(my_data, aes(x = Condition, y = Accuracy)) +
geom_boxplot(aes(fill = Condition), alpha = 0.2, col = "grey") +
geom_point(aes(col = Condition)) +
geom_line(aes(group = Patient))
With differentially coloured lines, you have to work out whether there's an increase or decrease before you do your plotting call:
# black = increased, red = decreased
my_data %>%
tidyr::spread(Condition, Accuracy) %>%
dplyr::mutate(is_increasing = condition2 > condition1) %>%
tidyr::gather("Condition", "Accuracy", 2:3) %>%
ggplot(aes(x = Condition, y = Accuracy)) +
geom_boxplot(aes(fill = Condition), alpha = 0.2, col = "grey") +
geom_point() +
geom_line(aes(group = Patient, col = is_increasing)) +
scale_colour_manual(values = c("red", "black"))
BTW, the data passed to ggplot now looks like this:
Patient is_increasing Condition Accuracy
1 P1 FALSE condition1 -0.6264538
2 P2 TRUE condition1 0.1836433
3 P3 TRUE condition1 -0.8356286
4 P4 FALSE condition1 1.5952808
5 P5 FALSE condition1 0.3295078
6 P1 FALSE condition2 -0.8204684
7 P2 TRUE condition2 0.4874291
8 P3 TRUE condition2 0.7383247
9 P4 FALSE condition2 0.5757814
10 P5 FALSE condition2 -0.3053884
Then make-up some data that conforms to the data structure that you are working with
See the help for tidyr::gather and look what happens after each step of data-manipulation that I gave you. Those are the columns that are gathered into the Accuracy column (of the output data) from the spread version of the data.
@russhh, Below is fraction of my data
condition,Accuracy,Patient
A,9510000,a A,762000,b A,630000,c A,98800,d A,6120000,e A,1.01E+06,f A,91200,g A,13700,h A,1.24E+05,i A,14500,j A,3680000,k B,3300,a B,1.10E+04,b B,59200,c B,57200,d B,3080,e B,75800,f B,2.28E+05,g B,6930,h B,54000,i B,35600,j B,9630,k I having problem to get the graph as you have nicely shown. Could you please try with the subset of data. Sorry, I don't know how to upload the data as csv file. Thanks
I suggest you to create two different dataframes, one with increased values, another with decreased values.
Then with the documentation ( https://cran.r-project.org/web/packages/ggpubr/ggpubr.pdf )
ggpaired(data, cond1, cond2, x = NULL, y = NULL, id = NULL,
color = "black", fill = "white", palette = NULL, width = 0.5,
point.size = 1.2, line.size = 0.5, line.color = "black", title = NULL,
xlab = "Condition", ylab = "Value", facet.by = NULL,
panel.labs = NULL, short.panel.labs = TRUE, label = NULL,
font.label = list(size = 11, color = "black"), label.select = NULL,
repel = FALSE, label.rectangle = FALSE, ggtheme = theme_pubr(), ...)
You can change the color of your lines with the line.color
option
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
post your code and I'll tweak it
For example