![]() Main = "Flower Characteristics in Iris") # plot title Legend(x = 4.5, y = 7, legend = levels(iris$Species), col = c(1:3), pch = 16)įINAL PLOT plot(iris$Sepal.Length, iris$Petal.Length, # x variable, y variable Keep this in mind for the next part! plot(iris$Sepal.Length, iris$Petal.Length, Therefore, setosa, versicolor and virginica will correspond to 1, 2 and 3 on the plot default colours. iris$Species is a factor, and R will automatically order factors in alphabetical order. This is one of the major drawbacks with R. It's difficult to tell these points apart, so perhaps we should make a legend. We can change the size of the points with “cex” plot(iris$Sepal.Length, iris$Petal.Length, Plot(iris$Sepal.Length, iris$Petal.Length, col = iris$Species, pch = 16) ![]() Pch 21:25 also specify an edge colour (col) and a background colour (bg) plot(iris$Sepal.Length, iris$Petal.Length, col = iris$Species, pch = 21, bg = "blue") Plot(iris$Sepal.Length, iris$Petal.Length, col = iris$Species, pch = "A") Plot(iris$Sepal.Length, iris$Petal.Length, col = iris$Species, pch = 15) These points are difficult to see! Let's pick some different ones using “pch” plot(iris$Sepal.Length, iris$Petal.Length, col = iris$Species) Again, we will specify colour as the Species. Sepal.Length and Petal.Length look interesting! Let's start by looking at that. We can tell R to plot using a different colour for the three species of iris: pairs(iris, col = iris$Species) This doesn't tell us much about the species differences. There is a lot of data here! Let's explore using the 'pairs' function pairs(iris) # Sepal.Length Sepal.Width Petal.Length Petal.Width Species Let's load a dataset of Flower characteristics in 3 species of Iris. Main = "Moomin Population Size on Ruissalo 1971 - 2001") # plot titleįit1 <- lm (PopSize ~ Year, data = moomins) # carry out a linear regressionĪbline(fit1, lty = "dashed") # add the regression line to the plot #~~ We can add some text to the plot giving the R2 value and the P value using "text" and specifying the x and y coordinates for the text. # F-statistic: 242 on 1 and 28 DF, p-value: 2.61e-15Ībline(fit1, lty = "dashed") #abline(a = intercept, b = slope) # Multiple R-squared: 0.896, Adjusted R-squared: 0.893 # Residual standard error: 35.6 on 28 degrees of freedom Before you get started, you should be familiar with the follow concepts: Vectors! height |t|) Preface: What am I supposed to know again? Boxplot with reordered and formatted axesĠ. I hope someone out there finds this useful - all code and datafiles are available here. In this blog post, I am providing some of the slides and the full code from that practical, which shows how to build different plot types using the basic (i.e. Last year, I presented an informal course on the basics of R Graphics University of Turku. However, with a basic knowledge of R, just investing a few hours could completely revolutionise your data visualisation and workflow. Making the leap from chiefly graphical programmes, such as Excel and Sigmaplot. Plots can be replicated, modified and even publishable with just a handful of commands. One of the most powerful functions of R is it's ability to produce a wide range of graphics to quickly and easily visualise data. R Base Graphics: An Idiot's Guide R Base Graphics: An Idiot's Guide
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |