Gundala Viswanath
2013-Jun-25 09:09 UTC
[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") -------------- next part -------------- A non-text attachment was scrubbed... Name: test.pdf Type: application/pdf Size: 41397 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130625/8257c29b/attachment-0001.pdf>
Blaser Nello
2013-Jun-25 09:58 UTC
[R] How to include ifelse condition to adjust QPLOT font size
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")