University of Sheffield



Recap/Intro – Functions, objects and working in the consoleWorking in the console is different from working with a GUI because…A function in R is…An object in R is…When we import a dataset it will be stored as…Using $ …Attaching a dataframe …Data DisplayA fun place to see bad data display Language warning – there is some swearing on this siteFinding a Functiona. What do you want to do?b. Is there a function in R what will help? - use an internet searchc. How do we use the function (what arguments does it take, in what order, how do we enter them) – use the help in RStudio and the internetArguments with Default ValuesYou know an argument has a default value if…Changing the default value…The order we enter arguments …Some examples of R Functions for Data DisplayA higher level graphing function…This is an introduction. We can’t possibly cover every chart and every setting. We’ll cover a few examples and the principle for finding out about others.Bar Charts…The table() function…Box Plots…Histograms…Scatter…ExerciseLook at the dataset “mtcars” (this is available by default in RStudio, just type mtcars in the console)Plot a bar chart/boxplot/histogram of any column.Plot a scatter graph of any two columns.Graphical ParametersPlaces to look up parameters for your reference: the colour…For more on colours see the axes…Changing the scale on the axes…Giving the graph a title…Plotting Character…Line type (lty)…0Blank1Solid2Dashed3Dotted4Dotdash5Longdash6Twodashtype…“p”points“l”Lines“b”Both“o”Overplotted“s”StepsExerciseReturn to your plots from the mtcars dataset (see previous exercise)Change the parameters to give your graph a title and change the axes titles.Play with the parameters col, pch, type and lty.Using ggplot2Tidyverse…ggplot2…Example:13335006985ggplot (data = )+4486275889030765755080600075-4445geom_ (mapping = aes( x= , y = ))using “+” at the end of the line…geoms…Some GeomsSmoothPointBoxplotaes…Some AestheticsLinetypeShapeColor (and fill)GroupExerciseRepeat the previous two exercises using the ggplot functionSome Useful links for GGplot2A helpful walk through in more detail. I’d recommend an hour or two going through this carefully from the start to really get to grips with ggplots: introduction: details for your reference good place to look up how to make a many kinds of graph (in ggplot2): ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download