Changing colour of dots group wise
2
0
Entering edit mode
21 months ago
Angel ★ 4.1k

Hi

I am visualising the difference of mutation burden between to group

My data looks like this

> head(tmb)
Response    variable value
1 Responders total_perMB  0.14
2 Responders total_perMB  0.98
3 Responders total_perMB  1.10
4 Responders total_perMB  1.16
5 Responders total_perMB  1.18
6 Responders total_perMB  1.26
>

> tail(tmb)
Response    variable value
59 Non-responders total_perMB  2.46
60 Non-responders total_perMB  2.54
61 Non-responders total_perMB  2.58
62 Non-responders total_perMB  2.70
63 Non-responders total_perMB  2.74
64 Non-responders total_perMB  3.42
>


I used this

> ggplot(tmb, aes(x=Response, y=value),color=Response) +
+     geom_quasirandom(size = 2, method = "frowney",width=0.3,color="navyblue")+ stat_summary(fun.data=data_summary, color="red")+labs(title="Plot of length  by dose",x="", y = "Total Mutation Burden per Mega base")+
+     theme_classic2(base_size =18)+stat_compare_means(aes(group = Response),method = "t.test", size=6)
>


I got this

But I want groups in different colours which I don't know how to change

R ggplot2 • 826 views
0
Entering edit mode

You're using facets, correct? There's an option to let the scales be free (i.e. independent of each other) - you can check if that works. If not, you can generate 2 plots and use cowplot or grid.arrange to "combine" them so they're side-by-side.

0
Entering edit mode

The first plot coming from maftools and no way to do the same scale, by plotting one by one again the scale to line the median for two groups is different so that I plotted by box which is fine but my boss demands something which is not box plot or violin

1
Entering edit mode

Try to include color=Response between aes(), like this:

gplot(tmb, aes(x=Response, y=value, color=Response))


Then I think you need to remove the color="navyblue" option from geom_quasirandom(). Otherwise not sure if it'll work properly.

António

0
Entering edit mode

Thank you I tried to change default colouring as green and red by scale_fill_manual(values=c("#999999", "#E69F00")) but not working

1
Entering edit mode

Did you try scale_color_manual(values=c("#999999", "#E69F00"))?

4
Entering edit mode
21 months ago
H.Hasani ▴ 990

In short yes, you can use ggbeeswarm to plot the individual observations along with with ggsignif to produce the statisics. However, if you are comparing the two groups that were measured by the same scale (MB) then you should plot them on the same scale, it will avoid misinterpreting the data & delevers the plot's message clearly & correctly

hth

2
Entering edit mode
21 months ago
antonioggsousa ★ 2.5k

Hi,

Yes, you can with facet_wrap() scales="free" or scales="free_y" only. See below:

## library
library("ggplot2")

## create df
Response <- rep( c("Responders", "Non-responders"), each = 6 )
Variable <- rep("total_perMB", 12)
value <- c(0.14, 0.98, 1.10, 1.16, 1.18, 1.26,
2.46, 2.54, 2.58, 2.70, 2.74, 3.42)
df <- data.frame(Response, Variable, value)

## plot
ggplot(data = df, aes(x = Response, y = value)) +
geom_point() +
facet_wrap(~Response, scales = "free") +
theme_minimal() +
ylab("TMB/MB")


Though I don't see which is your x-axis column. I'm mean if you have two numerical axis in a plot, you need to provide data with two numerical columns to ggplot2.

António