ggplot density plot: unequal columns

97 views
Skip to first unread message

zedias chikwambi

unread,
Jul 20, 2012, 7:59:51 AM7/20/12
to ggplot2 (ggplot2@googlegroups.com)
Hie

I am trying to plot a simple density plot from a table with four unequal columns but without success. I can plot the individual columns, but combining all four is proving to be a challenge.

This is what I have done:

> Trin_test<-read.table("triPE_trinPEs_Ab2_G2_length.txt", header=TRUE)
> ggplot(Trin_test, aes(Trin_test$Trin_trans_length.bp, fill=Trin_test$Trin_trans_length.bp)) + geom_bar(width=0.1, colour="white")
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
> ggplot(Trin_test, aes(Trin_test$Trin_trans_length.bp, fill=Trin_test$Trin_trans_length.bp)) + geom_density(width=0.1, colour="white")
> ggplot(Trin_test, aes(Trin_test$Trin_trans_length.bp, fill=Trin_test$Trin_trans_length.bp)) + geom_density(width=0.1, colour="green")
> assemb_test<-c("Trin_trans_length.bp.", "transcript_length.bp.", "Ab2_trans_length.bp.", "G2_trans_length.bp." )
> ggplot(Trin_test, aes(Trin_test$Trin_trans_length.bp, fill=assemb_test)) + geom_density(width=0.1, colour="green")
Error: Aesthetics must either be length one, or the same length as the dataProblems:assemb_test
> ggplot(Trin_test, aes(Trin_test, fill=assemb_test)) + geom_density(width=0.1, colour="green")
Error in data.frame(x = list(Trin_trans_length.bp. = c(1344L, 3049L, 626L,  :
  arguments imply differing number of rows: 134422, 4

Can someone help?

Attached is the data set am using.




--
Zedias Chikwambi

'' just one step at a time''
triPE_trinPEs_Ab2_G2_length.txt

John Kane

unread,
Jul 21, 2012, 7:52:00 PM7/21/12
to ggp...@googlegroups.com

Do a str() on the data.

As far as I can see you have one integer and 3 factors. 
If nothing else, I think that you have to convert all those * into NAs.

I have no idea of what will happen then, but currently it looks like you have an unuseable data.frame.

BTW you don't need
ggplot(Trin_test, aes(Trin_test$Trin_trans_length.bp, fill=Trin_test$Trin_trans_length.bp))

ggplot(Trin_test, aes(Trin_trans_length.bp, fill=Trin_trans_length.bp)) is fine and for a reader renaming the dataset: something like names(mydata)  <-  c( "t1", "t2", "a1", "g1") would give
ggplot(Trin_test, aes(t1, fill=t1))

which would be a lot easier to read.
Reply all
Reply to author
Forward
0 new messages