I'm trying to plot a bar graph of this data
The R script I have written so far is as follows:
library(ggplot2)
f<-read.table("Coverage_test", sep="\t", header=TRUE)
f$Coverage <- factor(f$Coverage, levels=unique(as.character(f$Coverage)))
g = ggplot(data=f, aes(x=Coverage, y=Variable_counts, group=Form, fill=Type))
+ geom_bar(position="dodge", stat="identity", colour="black")
+ facet_grid( ~ Sample_name, scales="free") + opts(title = "Coverage", axis.text.x = theme_text(angle = 90, hjust = 1, size = 8, colour = "grey50"))
+ ylab("Number of variables") + scale_fill_hue() + scale_y_continuous(formatter="comma")
ggsave("Figure_test_coverage.pdf")
The output of this code is as follows:

My question is:
Is there a way to show differences in the behavior of graph based two variables. Each x-axis variable has four bars. I've already chosen to fill the color by 'Type', this shows how different 'Type' (one variable) behaves in my data. But I also want to show how the variable 'Form' behaves in my data. I have grouped them in my code 'group=Form' but can't differentiate it in the actual graph (visually). This can be done in line plots by showing different colors for one variable and different linetypes(solid and dashed) for the other variable. Something like below:
.
I want to know if the 'Form' variable can be shown by different color or atleast can be named below their respective bars or anything that is possible? Any help is greatly appreciated.
Thank you.
I think you want something like this :
ggplot(data=dat, aes(x=Coverage,
y=Variable_counts,
group=interaction(Form,Type),
fill=interaction(Form,Type))) +
geom_bar(position="dodge", stat="identity", colour="black")

EDIT
Here I would lattice because of barchart and samrt formula notation. For fun I use a ggplot like theme using latticeExtra.
library(latticeExtra)
barchart(Variable_counts~Coverage|Sample_name,
groups=interaction(Type,Form),
data=dat,stack=F,auto.key=list(columns = 4),
par.settings = ggplot2like(),
axis = axis.grid,
between=list(x=2))

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With