qplot() stands for Quick Plot. It is an easy to use plotting tool for R. In order to use qplot(), you need to have ggplot2 installed. To see if you have it, just type the following:
If you get an error, you will need to install the package. To install package:
Okay, now let’s get some data. R comes will a great collection of data sets you can work with. You can search Google for R data sets. A great source is also the following webpage: https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/00Index.html
I have decided for this exercise to use the ChickWeight data set listed below.
To access the dataset in R, simply use the name.
As you can see, the data set contains 4 columns, weight, Time, Chick, Diet
Using qplot(), we can get right down to plotting. The basic syntax is: qplot(data, x value)
qplot(data=ChickWeight, x = weight)
Notice qplot() automatically labeled our axis. It even created automatic bins for us.
Let’s add a y value
qplot(data=ChickWeight, x = weight, y = Time)
Let’s add Diets to the mix now.
qplot(data=ChickWeight, x= weight, y = Time, color =Diet)
What jumps out at me right away is the fact the Diet 1 always seems to trail in weight, while Diet 4 seems to lead in weight gain in the earlier weeks, but it is overtaken by 2 and 3 starting around week 12.
Now let us add a size element to our graph
qplot(data=ChickWeight, x= Time, y = Chick,size=weight, color =Diet)
Now we have Chick’s on the y axis, Time on the X, the size of the dot correlates to weight and the color is diet.
The first thing I notice now is that our data is skewed. We have a lot more chicks on diet 1 than on the other 3 diets. That could effect how we read this data.
And finally, one more just for fun.
qplot(data=ChickWeight, x= weight, y = Chick, color =Diet)
2 thoughts on “R: Intro to qplot()”
Can I just say what a comfort to discover someone who really knows what they’re
discussing on the internet. You actually realize how to bring an issue to
light and make it important. More people should check this
out and understand this side of your story. I can’t believe
you’re not more popular because you most certainly have the gift. http://www.marinsbertoldi.com.br/