[R] How can I add text in plot and x axis of figures created in ggplot2?

Marna Wagley marna.wagley at gmail.com
Thu Sep 1 01:35:29 CEST 2016


Hi R users,
I have created four figures using ggplot2, but I am having trouble  to add
"r2=XXX, p=XX" value on the upper left in each figure and also unit of X
axis of each figure are different. I was also trying to write following  :
1.  "rainfall (mm/year") on X axix for fig A.
2. "temp (degree Celsius)" on X axis for fig B
3.  "distance (m)" on X axis for fig C
4.  "survival Proba(%) on X axis for fig D

I am wondering how I can create the figures with the above information

Thank you for your help in advance

Sincerely,

Marna

following code and the example I have used.

dat<-structure(list(x = c(0.31, 0.04, 0.1, 0.54, 0.03, 0.86, 0.97,

0.4, 0.62, 0.3, 0.44, 0.51, 0.03, 0.12, 0.79, 0.3, 0.22, 0.66,

0.75, 0.45), y = c(0.38, 0.61, 0.16, 0.06, 0.42, 0.67, 0.85,

0.11, 0.79, 0.21, 0.84, 0.95, 0.3, 0.47, 0.79, 0.2, 0.34, 0.21,

0.62, 0.25), group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,

2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L), .Label = c("A",

"B", "C", "D"), class = "factor")), .Names = c("x", "y", "group"

), class = "data.frame", row.names = c(NA, -20L))


gp<-ggplot(data=dat, aes(x=x, y=y))

Gp<-gp + geom_point(size=1, col="blue")

Gp<-Gp+ stat_smooth(method="lm", level=0.99, col="black",formula=y~poly(x,1
))+

coord_cartesian(ylim=c(0, 1))+theme_bw()+

theme(axis.text.y = element_text(angle = 90, vjust = 0))+

ylab <http://docs.ggplot2.org/0.9.2.1/labs.html>*(*"My Y"*)+*theme(
axis.text.x = element_text(size=8))

Gp+ facet_wrap(~group,ncol=5, scales="free_x")

	[[alternative HTML version deleted]]



More information about the R-help mailing list