2.6 Input- Getting Data into the Right Format

How does the qplot function differ from ggplot?

It creates plots from variables that are not already in a data frame


Use the qplot function (not ggplot) to create a scatterplot showing the relationship between the carat (x-axis) and price (y-axis) columns in the diamonds dataset

qplot(diamonds$carat, diamonds$price)


Load the reshape2 package.

library("reshape2")


The french_fries dataset is provided with the reshape2 package as an example. It contains sensory measurements testing the effect of three different fryer oils on how fries tasted.


Load the french_fries dataset.

data("french_fries")


View the french_fries dataset like a spreadsheet.

View(french_fries)


Each subject in the french_fries dataset was queried about five flavors ("potato", "buttery", "grassy", "rancid", "painty"). Currently, each flavor the subjects were asked about is a separate column.


Create a boxplot comparing the "buttery" rating between each of the three oils (oil is denoted by the "treatment" column).

ggplot(french_fries, aes(treatment, buttery)) + geom_boxplot()


Use reshape2's "melt" function create a new dataset, "french_fries.m", such that each tasting of each flavor has a separate row. There should be one column called "variable" containing the flavor name ("potato", "buttery", etc) and one column called value containing the numeric rating.

french_fries.m = melt(french_fries, id=c("time", "treatment", "subject", "rep"))


Use french_fries.m to create a boxplot comparing the taste rating between each of the three treatments (oils), but divide it into faceted subplots based on which flavor (buttery, potato) is being tested.

ggplot(french_fries.m, aes(treatment, value)) + geom_boxplot() + facet_wrap(~ variable)