Plot (x ,x * 2 ,col = 'red' ,type = 'l' ) Par (mfrow =c ( 2, 3 ) ) #Plot out the graphs using various options. Plot (x ,y ,pch =c ( 4, 5, 6 ) ,col =c ( 'red', 'blue', 'violet', 'green' ) ) Combining Plots In RĪ few more graphs using various options from above are illustrated below. #Set a plotting window with one row and two columns. We only need to set the space before calling the plot function in our graph. R also allows combining multiple graphs into a single image for our viewing convenience using the par() function. We are now enabling the compiler to select from 3 different symbols and 4 different colors for marking the graph. Let us now try changing the symbols and colors. Let x be a sequence vector of values from -pi to pi with 0.1 intervals and y contains the respective sine values of x. We will begin by generating a sine wave plot. Let us now try constructing a few graphs with what we learned so far. Varying the lines: The line type can be specified by the lty parameter (range 0 to 6) and line width is set using an lwd parameter.To get a histogram like display the ‘h’ option is used and ‘s’ is used for a step option. Similarly, values ‘b’ and ‘o’ are for lines connecting points and overlaying points respectively. The type attribute set to ‘p’ refers to only points and ‘l’ to only a line. This can be done using the type attribute of the plot function. Connecting the points with lines: Many times, it is necessary to connect the displayed points with different kinds of lines.These colors can be selected from a list provided by R under the colors() function. Color of the plot markers: The symbols can be assigned one or many colors.The cex parameter can be set to 0.5 if you want the markers to be 50% smaller and 1.5 if you want them to be 50% larger. Size of the plot markers: This aspect of a graph can be controlled using the cex parameter.Pch 0 is for a square, 1 is for a circle, 3 is for a triangle, 4 is for a cross and so on. Pch values 0 to 25 are valid and give several different symbols on the graph. You can change these by adding a new pch value in the plot function. These are also known as plot characters - denoted by pch. The shape of the markers: The plot markers are by default small, empty circles.The plot() function in R can be customized in multiple ways to create more complex and eye-catching plots as we will see. Square plot in R Changing Graph Appearance with the plot() function in R At its simplest, plot() function simply plots two vectors against each other. The exact function being called will depend upon the parameters used. The plot() function in R isn’t a single defined function but a placeholder for a family of related functions. The R language is well known for its beautiful graphics with a rich set of functions to build and format any kind of graphs and the plot() function family one that helps us build those. Two of these single number arrays can then be bundled together to create a single XY point data, ready for the XY graph to accept.In this tutorial, let us first begin by understanding the basics using the plot() function in R.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |