Manisha Brahma chary
2013-Jul-19 21:17 UTC
[R] Using text and variable in ggtitle (ggplot2)
Hello, I am using ggplot2 to plot a graph and I want to give a title to the plot that has both text and variables. I have tried a couple of ways, but none of the methods work. Below is my code. Under ggtitle RR, N, alpha1 are variables and "RR(overall), "N", "alpha" are strings. Require(ggplot2) data <- do.call(rbind,result) data.new <- as.data.frame(cbind(data$p1,(data$prob),data$r)) colnames(data.new) <- c("ES","Probability","Vector") bp<-(ggplot(data.new,aes(x=ES,y=Probability,group=Vector,colour=factor(Vector))) + geom_line()) bp.title<- bp+ ggtitle("RR(overall) ="RR, "N" = N, "alpha = "alpha1) bp.title Any suggestion on ggplot2 will be much appreciated. Thanks Man [[alternative HTML version deleted]]
Not sure whether I understand your question fully but I guess paste() is your friend: ggtitle( paste( "RR(overall) =", RR, "N =", N, "alpha =", alpha1 ) ) On Friday 19 July 2013 17:17:24 Manisha Brahma chary wrote:> Hello, > I am using ggplot2 to plot a graph and I want to give a title to the plot that has both text and variables. I have tried a couple of ways, but none of the methods work. Below is my code. Under ggtitle RR, N, alpha1 are variables and "RR(overall), "N", "alpha" are strings. > > Require(ggplot2) > data <- do.call(rbind,result) > data.new <- as.data.frame(cbind(data$p1,(data$prob),data$r)) > colnames(data.new) <- c("ES","Probability","Vector") > bp<-(ggplot(data.new,aes(x=ES,y=Probability,group=Vector,colour=factor(Vector))) + geom_line()) > bp.title<- bp+ ggtitle("RR(overall) ="RR, "N" = N, "alpha = "alpha1) > bp.title > > Any suggestion on ggplot2 will be much appreciated. > > Thanks > Man > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.- - - - - Der NSA keine Chance: e-mail verschluesseln! http://www.gpg4win.org/