How to add illustrative bar in ggplot2?
1
0
Entering edit mode
18 months ago
Amr ▴ 160

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 • 918 views
ADD COMMENT
0
Entering edit mode
18 months ago

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

ADD COMMENT
0
Entering edit mode

enter image description here

Something like the data bar on the right

ADD REPLY
1
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
1
Entering edit mode

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

ADD REPLY
0
Entering edit mode

Yes sure, thanks for help :)

ADD REPLY

Login before adding your answer.

Traffic: 1540 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