Plotting Data
In order to make a scatterplot in order to perform generic x, y plotting, use the following: plot(x, y, …)
- To practice this, let's use the following csv file. http://joeystanley.com/downloads/menu.csv Links to an external site.. To load the data into R type: data<-read.csv("http://joeystanley.com/downloads/menu.csv")
- Type the following into the script: plot(data$Calories,data$Fat). Calories will be on the x-axis, fat will be on the y axis.
- Then, press Run.
- A plot will come up on the bottom right-hand corner on your screen.
- Now let's make a histogram.
- The function to make a histogram is the following: hist().
- Using the dataset above, you can make a histogram of the Calories in the foods from lines 1-57.
- Type the following into your script: x<-(data$Calories[1:57]) hist(x)
- The plot should look like the following in plots on the bottom left hand side of your screen.
Now try making plots on your own!