[R] How to include ifelse condition to adjust QPLOT font size

Blaser Nello nblaser at ispm.unibe.ch
Tue Jun 25 11:58:45 CEST 2013


If you want the size to depend on the data, then size needs to be inside
aes(...). For instance:
stat_bin(aes(label = sprintf("%.01f", (..count../288)*100),
size=ifelse(..count..>0, 2.5, 0)) ,color="red", vjust=-0.5, angle=0,
geom="text")

A better approach would be not to plot the unnecessary things at all.
This should do it:
stat_bin(aes(label = ifelse(..count..>0, sprintf("%.01f",
(..count../288)*100), "")), size=2.5,color="red", vjust=-0.5, angle=0,
geom="text")

Best, 
Nello


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Gundala Viswanath
Sent: Dienstag, 25. Juni 2013 11:09
To: r-help at r-project.org; r-help at stat.math.ethz.ch
Subject: [R] How to include ifelse condition to adjust QPLOT font size

I have a data which I plot using this code.
Attached is the plot

_BEGIN_
library(ggplot2)
dat.m <- read.delim("http://dpaste.com/1269939/plain/",sep="")
colnames(dat.m) <- c("ensg","mirna_hgc","variable","value")
dat.m.y <- subset(dat.m,dat.m$variable=="y") qplot(value,data=dat.m.y,
geom="bar",  origin=-0.05, xlim=c(48,101),ylim=c(0,75),
facets=variable~.,main="")+ xlab("Value")+ ylab("Frequency")+
theme(legend.position="none")+ stat_bin(aes(label = sprintf("%.01f",
(..count../288)*100)),size=2.5,color="red", vjust=-0.5, angle=0,
geom="text")
__END__

What I wan't to do is to get rid of the barplot labels when the value in
red is 0.0.
How can I go about it?

I tried this but it won't work
stat_bin(aes(label = sprintf("%.01f",
(..count../288)*100)),size=ifelse(dat$m.y>0,2.5,0),color="red",
vjust=-0.5, angle=0, geom="text")



More information about the R-help mailing list