Hi all, Small problem in generating the line charts.
Question: Legend for the first graph is coming wrong., for second graph correctly. Please fix the legend postion at the down of graph. Plesae give me the solution. Thank you Devarayalu Orange1 <- structure(list(REFID = c(7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9), ARM = c(1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2), SUBARM = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ACTTRT = structure(c(3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L), .Label = c("ABC", "DEF", "LCD", "Vehicle"), class = "factor"), TIME1 = c(0, 2, 6, 12, 0, 2, 6, 12, 0, 2, 6, 12, 0, 2, 6, 12, 0, 12, 0, 12), ENDPOINT = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "PGA", class = "factor"), BASCHGA = c(0, -39, -47, -31, 0, -34, -25, -12, 0, -45, -47, -20, 0, -25, -30, -35, 0, -30, 0, -40), STATANAL = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "UNK", class = "factor"), Art_Name = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Bela_2010_206878", "Dansinger_2010_20687812" ), class = "factor")), .Names = c("REFID", "ARM", "SUBARM", "ACTTRT", "TIME1", "ENDPOINT", "BASCHGA", "STATANAL", "Art_Name" ), row.names = c(NA, 20L), class = "data.frame") unique(Orange1$REFID) -> refid # Create Line Chart for (i in 1:length(refid)) { # convert factor to numeric for convenience refid1 <- subset(Orange1, REFID == refid[i]) refid1$ACTTRTnum <- as.numeric(refid1$ACTTRT) nACTTRTs <- max(refid1$ACTTRTnum) # get the range for the x and y axis xrange <- range(refid1$TIME1) yrange <- range(refid1$BASCHGA) # set up the plot pdf (paste("pga", i, ".pdf", sep='')) print(plot(xrange, yrange, type="n", xlab="TIME1 (WK)", ylab="BASCHGA (mm)" )) colors <- rainbow(nACTTRTs) linetype <- c(1:nACTTRTs) plotchar <- seq(18,18+nACTTRTs,1) # add lines for (i in 1:nACTTRTs) { ACTTRT <- subset(refid1, ACTTRTnum==i) print(lines(ACTTRT$TIME1, ACTTRT$BASCHGA, type="b", lwd=1.5, lty=linetype[i], col=colors[i], pch=plotchar[i])) } # add a title and subtitle paste("REFID = ", unique(refid1$REFID), "; STATANAL = ", unique(refid1$STATANAL), sep="") -> x title(x) # add a legend legend(xrange[1], yrange[2], unique(refid1$ACTTRT), cex=0.8, col=colors, pch=plotchar, lty=linetype) #"bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" and "center" dev.off() } [[alternative HTML version deleted]] ______________________________________________ R-help@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.