Always try to work with a minimal working example and state whether or not the code you're presenting is complete or you're leaving something out.
From your question it is hard to know if what you've pasted is all there is to your code or if you have tried something else.
The line qplot(carat, price, data = dsmall, colour = color) does four things:
- It invokes qplot and tells it to plot some data.
- Tells qplot to plot the values in the carat column of the provided dataset against the values in the price column from the same dataset.
- Provides a symbol dsmall as data source for qplot to use. dsmall must be defined by the time qplot is invoked.
- Specifies that the color column in the provided dataset should be used to determine the color of the plotted symbols.
Now, R is telling you Error in eval(expr, envir, enclos) : object 'color' not found. This means, the column color hasn't been found in the provided datasource. This leads me to believe that you haven't appropriately prepared the dsmall datasource and hence you're having problems with the plot.
Try running the following code as provided in your console:
library(ggplot2)
set.seed(1410)
dsmall <- diamonds[sample(nrow(diamonds), 100), ]
head(dsmall)
qplot(carat, price, data = dsmall, colour = color)
Resulting plot
dsmall? What does it look like? Basically the error is telling you that there isn't a column named "color" in your data set.dsmall <- diamonds[sample(nrow(diamonds), 100), ]. Did you create that object? If you look at the details ('str(dsmall)'), you should see "color" is a valid column.dsmalldefinition line. It is misleading becausediamondsis defined in theggplot2library, but then the examples in Hadley's ggplot2 book often run ondsmall.