All ggplot2 plots begin with a call to ggplot(), supplying default data and aesthethic mappings, specified by aes().
You then add layers, scales, coords and facets with +.
To save a plot to disk, use ggsave()
- ggplot() Create a new ggplot
- aes() Construct aesthetic mappings
-
+
(<gg>)%+%
Add components to a plot - ggsave() Save a ggplot (or other grid object) with sensible defaults
- qplot() quickplot() Quick plot
- geom_boxplot() stat_boxplot() A box and whiskers plot (in the style of Tukey)
- labs() xlab() ylab() ggtitle() Modify axis, legend, and plot labels
- lims() xlim() ylim() Set scale limits
示例
library(ggplot2)
table=read.table("kaks.result.table",sep="\t",header=T)
pdf(file="ka2.pdf")
ggplot(table,aes(x=gene,y=ka,fill=gene))+geom_boxplot()+labs(x="Genes",y="Ka")
dev.off()
pdf(file="ks2.pdf")
ggplot(table,aes(x=gene,y=ks,fill=gene))+geom_boxplot()+labs(x="Genes",y="Ks")
dev.off()
pdf(file="kaks2.pdf")
ggplot(table,aes(x=gene,y=kaks,fill=gene))+geom_boxplot()+ylim(0, 5)+labs(x="Genes",y="Ka/Ks")
dev.off()
网友评论