Friday, March 25, 2016

Scatter plot in R ggplot2 using wesanderson palette

To plot a scatter plot in R using ggplot2 package use geom_point and to add some visually appealing color palettes. Install and load a wesanderson package and add it to your ggplot code with scale_color_manual.


> library (ggplot2)
> library (wesanderson)

> x<- read.delim("shown-GOBiologicalProcess.short.tsv", header=F)

> x
                                                         V1       V2        V3
1                                              ossification 8.868518  2.500906
2                             skeletal system morphogenesis 8.550280  2.381594
3                                      response to nutrient 8.495432  2.987107
4  regulation of protein import into nucleus, translocation 8.426276  9.436530
5                                        tyrosine transport 7.810678 21.485540
6                                          response to heat 7.566548  3.999154
7                                cell junction organization 7.435220  2.296243
8                   embryonic skeletal system morphogenesis 7.358300  2.930280
9                                    osteoblast development 7.150353  5.649584
10                                      response to vitamin 6.760223  3.561107
11                          cell-cell junction organization 6.756272  2.283825
12                 calcium-independent cell-matrix adhesion 6.739017 14.800580
13                         T cell differentiation in thymus 6.604179  3.837571
14                             cellular response to vitamin 6.595923  8.535726
15   dichotomous subdivision of an epithelial terminal unit 6.577308  6.239491
16                                      gland morphogenesis 6.556537  2.381006
17 establishment of protein localization to plasma membrane 6.492166  4.960975
18                   response to purine-containing compound 6.463773  2.947403
19                                    response to vitamin K 6.402319 34.013860
20                         eye pigment biosynthetic process 6.373886 13.015510


> p<- ggplot(x, aes(x=x$V3, y=x$V2, colour = V1)) + geom_point(shape=19, alpha=3/3, size=8) + xlab("Fold change") + ylab("-log P-value") + ggtitle ("GO Biological process enrichment in AHR-ARNT/TCF12 PWM overlaps")+xlim(0, 35)+scale_color_manual(name="GO Biological process",values = c(wes_palette("Cavalcanti"),wes_palette("GrandBudapest"), wes_palette("Royal1"), wes_palette("Royal2"), wes_palette("Moonrise2")))+ theme_gray()
> p
The resulting plot:




No comments:

Post a Comment