zero values being plotted inappropriately bellow zero

14 views
Skip to first unread message

Fernando Biase

unread,
Oct 31, 2013, 1:34:55 PM10/31/13
to ggp...@googlegroups.com
Hi all,

I have been using ggplot2 for a while, and I only now found a limitation I could not fix.
I have  set of plots that are "behaving" completely differently when I ask for the facet_wrap() with multiple identifiers.

My problem is that I the data does not have values bellow zero, but they are being plotted as such.

If you want to take a look at:

the problematic charts are on
row 1, column 2
row 2, column 3
row 3, column 2

If I subset my file and build the chart for the "problematic" identifiers, plus one, everything looks good.


Here is my code:

library(ggplot2)
setwd("/path/")
my_data<-read.delim("chart_data.txt")

ggplot(data=my_data, aes(x=group_embryo,y=(value)))+
  geom_point(aes( colour=factor(cell)),position = position_jitter(width = .3), size =4, alpha=0.5)+
  facet_wrap( ~ Associated.Gene.Name, scales ="free_y")+
  scale_y_continuous(name="(FPKM)")+
  scale_x_discrete(name="", labels=c("two_E1","two_E2","two_E3","two_E4","two_E5","two_E6","two_E7","two_E8","two_E9","two_E10","four_E1","four_E2", "four_E3","four_E4","four_E5"))+
  scale_colour_manual(name="Cells",values=c("red","blue", "black","green"))+
  #scale_shape_manual(values=c(15,16,17,18,8))+
  theme(
    axis.title.y=element_text(size=20, color="black"),
    axis.text.x=element_text(size=15, color="black", angle=90, vjust=0.1, hjust=1),
    axis.text.y=element_text(size=18, color="black"),
    panel.background=element_rect(colour="black", fill="white"),
    #panel.grid.major=element_blank(),
    panel.grid.minor=element_blank(),
    strip.background=element_rect(colour="black",fill="white"),
    strip.text=element_text(face="italic", size=15),
    panel.margin = unit(0.3,"cm")
  )


If someone can help, the file to reproduce the code is here:

Fully appreciate any help,
Fernando




Brian Diggs

unread,
Oct 31, 2013, 3:47:52 PM10/31/13
to ggp...@googlegroups.com
I can strip down your code to the more minimal

ggplot(data=my_data, aes(x=group_embryo,y=value))+
  geom_point(position = position_jitter(width = 0.3))+

  facet_wrap( ~ Associated.Gene.Name, scales ="free_y")

which still shows the problem. It is no coincidence that you are seeing the effect on the panels with the smallest range; what is happening is that all the points are being jittered vertically as well as horizontally. The vertical jittering is small on the scale of all the data, but large on the scale of a few of the facets. Add a height=0 argument to the position_jitter call and that will force there to be no vertical jittering (and thus no points below 0). (the facet_wrap is not necessary for this to happen, but is necessary to separate out certain panels so that the effect is large in those panels and noticeable).


> Fully appreciate any help,
> Fernando

--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

Fernando Biase

unread,
Oct 31, 2013, 3:58:58 PM10/31/13
to ggp...@googlegroups.com
Impressive!!!
thank you so very much Dr. Diggs,
Fernando
Reply all
Reply to author
Forward
0 new messages