This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to add illustrative bar in ggplot2?

How to add illustrative bar in ggplot2 for 3 dataframes together in one plot in R? enter image description here

I need to add illustrative bar beside the chart to illustrates every data for example: orange circle is for effect, blue rectangular for SD and so on.

ggplot() +               
  geom_point(data = significance, aes(s.dist,-log2(p.adjustMANOVA)), 
             fill = "darkorange1", color = "black",
             size = 7, shape = 21)+
  geom_point(data = effect, aes(s.dist,-log2(p.adjustMANOVA)), 
             fill = "cornflowerblue", color = "black", 
             size = 5, shape = 22)+
  geom_point(data = SD, aes(s.dist,-log2(p.adjustMANOVA)), 
             fill = "deeppink1", color = "black", 
             size = 4, shape = 23)+
  labs(x = "s.dist", y = "p.adjustMANOVA")+
  ggtitle("Significance vs Effect_size vs Standard_error")
ggplot2 r

1 answer

Do you have an example of what you want the final product to look like?

enter image description here

Something like the data bar on the right

What you are looking for is a legend. ggplot2 will automatically create one, if you combine your data into one dataframe beforehand (with a column each for x,y, and category) and just add one geom_point() layer. Please see the examples how to map the categorical variable to shape and color via aes().

Thanks, yes you are right I combined the data in one dataframe but I did it on python with pandas and plot it with matplotlib.

Fair enough. Whatever works for you is fine. I just pointed out how to do it in ggplot2, because you specifically asked for that.

Yes sure, thanks for help :)

Log in to answer this question.