makeframe: Display a single movie frame.invert: Invert and shift colors of an image.graphx: Graphics Routines for Scientific Research.errlines: Draw a line with uncertainty regions.cmplx2col: Convert complex numbers to color.Create a common legend for these subplots and place it to the right of the subplots. This is the point at which, if this were a textbook, I would ask you to “Create a 2 row 1 column plot in R using the layout command. The plot, after much adventure, looks like this: Png ( "subplot9.png", height = 4, width = 8, units = "in", res = 300 ) layout ( matrix ( c ( 1, 2, 3, 4, 4, 4 ), ncol = 3, byrow = TRUE ), heights = c ( 0.9, 0.1 ), widths = c ( 0.1, 0.45, 0.45 )) par ( mar = c ( 0, 0, 0, 0 )) # Make the margins 0 for y label plot ( 1, type = "n", axes = FALSE, xlab = "", ylab = "" ) # Create empty plot text ( 1, 1, labels = "Y", srt = 90 ) # Create y label par ( mar = c ( 4.0, 0.5, 0.5, 0.5 )) # Make the margins non-zero for plots plot ( x, y, xlab = "X1", ylab = "", col = c1, pch = 16 ) plot ( x, y, xlab = "X2", ylab = "", yaxt = "none", col = c2, pch = 16 ) par ( mar = c ( 0, 0, 0, 0 )) # Make the margins 0 for legend plot ( 1, type = "n", axes = FALSE, xlab = "", ylab = "" ) # Create empty plot legend ( x = 0.93, y = 1.25, c ( "Blue Points", "Orange Points" ), horiz = TRUE, pch = c ( 16, 16 ), col = c ( c1, c2 )) # Manual placement of legend dev.off () The legend will have to be manually placed. (Note that once altered, the margin values stay the same until they are altered again). The margins also have to be altered for the y label, the plots and the legend.The second and third parts will hold the plots. In the top row, the first part in the layout will hold the y label. The new layout should have 2 rows, but 3 columns.Some things to keep in mind while doing this: There are probably other ways to address this gap, but the solution that worked for me is creating a new layout to hold the common y axis label. You would think “Yes, that’s it! It’s done!”. Png ( "subplot8.png", height = 4, width = 8, units = "in", res = 300 ) layout ( matrix ( c ( 1, 2, 3, 3 ), ncol = 2, byrow = TRUE ), heights = c ( 0.9, 0.1 )) plot ( x, y, xlab = "X1", ylab = "Y", col = c1, pch = 16 ) plot ( x, y, xlab = "X2", ylab = "", yaxt = "none", col = c2, pch = 16 ) par ( mar = c ( 0, 0, 0, 0 )) # Make the margins 0 plot ( 1, type = "n", axes = FALSE, xlab = "", ylab = "" ) # Create empty plot legend ( "top", c ( "Blue Points", "Orange Points" ), horiz = TRUE, pch = c ( 16, 16 ), col = c ( c1, c2 )) dev.off () Then it makes sense to remove the y axis tick marks and the associated tick labels, we do this with the following snippet: Now suppose that the two plots share the same units on the y axis and also similar ranges of the data. The above command creates an empty plot, and the legend function can be called after this. Creating a legend is necessarily preceded by creating a plot in the first place. plot(1, type = "n", axes=FALSE, xlab="", ylab="") – This creates an empty plot.par(mar=c(0,0,0,0)) – The reason for the first part is that by default, the plot margins tend to be quite big.Png ( "subplot7.png", height = 4, width = 8, units = "in", res = 300 ) layout ( matrix ( c ( 1, 2, 3, 3 ), ncol = 2, byrow = TRUE ), heights = c ( 0.9, 0.1 )) plot ( x, y, xlab = "X1", ylab = "Y1", col = c1, pch = 16 ) plot ( x, y, xlab = "X2", ylab = "Y2", col = c2, pch = 16 ) par ( mar = c ( 0, 0, 0, 0 )) # Make the margins 0 plot ( 1, type = "n", axes = F, xlab = "", ylab = "" ) # Create empty plot legend ( "top", c ( "Blue Points", "Orange Points" ), horiz = TRUE, pch = c ( 16, 16 ), col = c ( c1, c2 )) dev.off ()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |