[R] Wie plotte ich mit ggplot2 einen Barplot?

Hoeze

Lieutenant
Registriert
Juni 2010
Beiträge
696
Hi,
ich generiere mir folgende Daten:
Code:
dat.matrix = matrix(
	c(
		"# reads", 
		length(dat.reads), 
		"# unspliced", 
		sum(dat.reads[,1] == 1),
		"# unspliced without mismatches", 
		sum(unlist(apply(dat.reads, 1, function(x) x[1]==1 && x[2] == 0))),
		"# split reads", 
		sum(dat.reads[,1] > 1),
		"# split reads without mismatches", 
		sum(unlist(apply(dat.reads, 1, function(x) x[1] > 1 && x[2] == 0))),
		"# split reads without mismatches and only regions longer than 5bp",
		sum(unlist(apply(dat.reads, 1, function(x) x[1] > 1 && x[2] == 0 && x[3])))), 
	ncol=2, 
	byrow=TRUE
)

Das Ergebnis sieht so aus:
Code:
> dat.matrix
     [,1]                                                               
[1,] "# reads"                                                          
[2,] "# unspliced"                                                      
[3,] "# unspliced without mismatches"                                   
[4,] "# split reads"                                                    
[5,] "# split reads without mismatches"                                 
[6,] "# split reads without mismatches and only regions longer than 5bp"
     [,2]      
[1,] "45938592"
[2,] "10610924"
[3,] "4993760" 
[4,] "4701940" 
[5,] "2212949" 
[6,] "1986802"

Wie erstelle ich daraus jetzt einen Barplot?
 
Hoeze schrieb:
Wie erstelle ich daraus jetzt einen Barplot?

So?
Code:
...
dm <- dat.matrix;
gp <- ggplot(data=melt(dm),aes(dm[,1],dm[,2],fill=dm[,1])) + 
      geom_bar(stat="identity") +
      guides(fill=FALSE)
print(gp)
...
 
Ah, danke.
Ich habs jetzt mit data.frame() auch hinbekommen, aber gut zu wissen :)
 
Zurück
Oben