Changing colour of dots group wise
2
0
Entering edit mode
4.4 years ago
zizigolu ★ 4.3k

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

enter image description here

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

R ggplot2 • 2.1k views
ADD COMMENT
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.

ADD REPLY
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

ADD REPLY
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

ADD REPLY
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

ADD REPLY
1
Entering edit mode

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

ADD REPLY
4
Entering edit mode
4.4 years 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

ADD COMMENT
2
Entering edit mode
4.4 years ago

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

enter image description here

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.

I hope this answers your question,

António

ADD COMMENT

Login before adding your answer.

Traffic: 1988 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6