Plotting barplot with bars by grouped/colored by group names
Well with this dataset in CSV format,
GO Biological Process,regulation of lipid metabolic process,1.87E-35
GO Biological Process,acute inflammatory response,3.21E-37
GO Biological Process,response to insulin stimulus,1.05E-38
GO Biological Process,steroid metabolic process,4.19E-39
GO Biological Process,cholesterol metabolic process,1.19E-40
GO Biological Process,cellular response to chemical stimulus,5.87E-42
GO Biological Process,alcohol metabolic process,5.27E-43
GO Biological Process,sterol metabolic process,2.61E-43
GO Biological Pr开发者_JAVA技巧ocess,lipid homeostasis,1.12E-44
GO Biological Process,response to peptide hormone stimulus,1.29E-45
GO Biological Process,monocarboxylic acid metabolic process,2.33E-54
GO Biological Process,cellular ketone metabolic process,5.46E-74
GO Biological Process,carboxylic acid metabolic process,2.41E-76
GO Biological Process,organic acid metabolic process,5.30E-79
Pathway Commons,FOXA transcription factor networks,7.40E-61
Pathway Commons,FOXA2 and FOXA3 transcription factor networks,1.39E-64
Transcription Factor Targets,"Targets of HNF6, identified by ChIP-chip in hepatocytes",1.77E-32
Transcription Factor Targets,"Targets of HNF1alpha, identified by ChIP-chip in hepatocytes",3.87E-65
Transcription Factor Targets,"Targets of HNF4alpha, identified by ChIP-chip in hepatocytes",1.38E-131
I would like to be able to create a plot (barplot?) that looks like this :
where the three different groups in column 1 are grouped together with the same color and the 3rd column is sorted from biggest to smalest. The plot above is made with excel but I would like to be able to make it properly in R. So far all I am getting is the 2nd and 3nd column plotted, I can't get the bars grouped by the 1st column.
Well I have tried ggplot as recommended. This is what I got (it looks brilliant btw) :
library(ggplot2)
ggplot(tmp, aes(x=tmp$V2, y=log(tmp$V3), fill=tmp$V1)) +
geom_bar(stat="identity") +
coord_flip() +
scale_y_log()
However, I need to find out how to "reverse" the axis such as [0, 1e-130] (eg. the bars go from left to right like in my example above)
This is reasonably straight-forward with ggplot
in the ggplot2
package. You can achieve this by specifying the fill colour in your plot, and mapping a column in your data to the fill, i.e. aes(..., fill=group)
:
library(ggplot2)
dat <- data.frame(
label=LETTERS[1:10],
value=10:1,
group=letters[c(1,1,2,2,2,3,3,3,3,3)]
)
dat
label value group
1 A 10 a
2 B 9 a
3 C 8 b
4 D 7 b
5 E 6 b
6 F 5 c
7 G 4 c
8 H 3 c
9 I 2 c
10 J 1 c
ggplot(dat, aes(x=label, y=value, fill=group)) +
geom_bar(stat="identity") +
coord_flip()
精彩评论