library(ggplot2)
summary(diamonds)
## carat cut color clarity
## Min. :0.200 Fair : 1610 D: 6775 SI1 :13065
## 1st Qu.:0.400 Good : 4906 E: 9797 VS2 :12258
## Median :0.700 Very Good:12082 F: 9542 SI2 : 9194
## Mean :0.798 Premium :13791 G:11292 VS1 : 8171
## 3rd Qu.:1.040 Ideal :21551 H: 8304 VVS2 : 5066
## Max. :5.010 I: 5422 VVS1 : 3655
## J: 2808 (Other): 2531
## depth table price x
## Min. :43.0 Min. :43.0 Min. : 326 Min. : 0.00
## 1st Qu.:61.0 1st Qu.:56.0 1st Qu.: 950 1st Qu.: 4.71
## Median :61.8 Median :57.0 Median : 2401 Median : 5.70
## Mean :61.7 Mean :57.5 Mean : 3933 Mean : 5.73
## 3rd Qu.:62.5 3rd Qu.:59.0 3rd Qu.: 5324 3rd Qu.: 6.54
## Max. :79.0 Max. :95.0 Max. :18823 Max. :10.74
##
## y z
## Min. : 0.00 Min. : 0.00
## 1st Qu.: 4.72 1st Qu.: 2.91
## Median : 5.71 Median : 3.53
## Mean : 5.73 Mean : 3.54
## 3rd Qu.: 6.54 3rd Qu.: 4.04
## Max. :58.90 Max. :31.80
##
set.seed(1410)
dsmall <- diamonds[sample(nrow(diamonds), 100), ]
summary(dsmall)
## carat cut color clarity depth
## Min. :0.230 Fair : 3 D:16 VS2 :22 Min. :56.9
## 1st Qu.:0.417 Good : 4 E:19 VS1 :20 1st Qu.:61.2
## Median :0.740 Very Good:28 F:15 SI2 :19 Median :61.8
## Mean :0.865 Premium :20 G:18 SI1 :19 Mean :61.8
## 3rd Qu.:1.202 Ideal :45 H:17 VVS2 : 9 3rd Qu.:62.5
## Max. :2.500 I: 8 VVS1 : 8 Max. :66.0
## J: 7 (Other): 3
## table price x y
## Min. :54.0 Min. : 353 Min. :3.95 Min. :3.98
## 1st Qu.:56.0 1st Qu.: 1001 1st Qu.:4.79 1st Qu.:4.78
## Median :57.0 Median : 3022 Median :5.82 Median :5.79
## Mean :57.4 Mean : 4533 Mean :5.86 Mean :5.86
## 3rd Qu.:59.0 3rd Qu.: 6712 3rd Qu.:6.71 3rd Qu.:6.76
## Max. :65.0 Max. :17841 Max. :8.56 Max. :8.48
##
## z
## Min. :2.44
## 1st Qu.:2.95
## Median :3.60
## Mean :3.62
## 3rd Qu.:4.24
## Max. :5.46
##
qplot(carat, price, data = diamonds)
qplot(log(carat), log(price), data = diamonds)
qplot(carat, x * y * z, data = diamonds)
qplot(carat, price, data = dsmall, colour = color)
qplot(carat, price, data = dsmall, shape = cut)
qplot(carat, price, data = diamonds, alpha = I(1/10))
qplot(carat, price, data = diamonds, alpha = I(1/100))
qplot(carat, price, data = dsmall, geom = c("point", "smooth"))
## geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.
qplot(carat, price, data = dsmall, geom = c("point", "smooth"), span = 0.2)
## geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.
qplot(carat, price, data = dsmall, geom = c("point", "smooth"), span = 1)
## geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.
library(mgcv)
## This is mgcv 1.7-13. For overview type 'help("mgcv-package")'.
qplot(carat, price, data = dsmall, geom = c("point", "smooth"), method = "gam",
formula = y ~ s(x))
qplot(carat, price, data = dsmall, geom = c("point", "smooth"), method = "gam",
formula = y ~ s(x, bs = "cs"))
library(splines)
qplot(carat, price, data = dsmall, geom = c("point", "smooth"), method = "lm")
qplot(carat, price, data = dsmall, geom = c("point", "smooth"), method = "lm",
formula = y ~ ns(x, 5))
library(MASS)
qplot(carat, price, data = dsmall, geom = c("point", "smooth"), method = "rlm",
formula = y ~ ns(x, 5))
qplot(color, price/carat, data = diamonds, geom = "jitter", alpha = I(1/100))
qplot(color, price/carat, data = diamonds, geom = "boxplot")
qplot(carat, data = diamonds, geom = "histogram", binwidth = 0.1,
xlim = c(0, 3))
qplot(carat, data = diamonds, geom = "histogram", binwidth = 0.01,
xlim = c(0, 3))
qplot(carat, data = diamonds, geom = "density")
qplot(carat, data = diamonds, geom = "histogram", binwidth = 0.1,
colour = color)
qplot(carat, data = diamonds, geom = "density", fill = color)
qplot(color, data = diamonds, geom = "bar")
qplot(color, data = diamonds, geom = "bar", weight = carat) + scale_y_continuous("carat")
qplot(date, unemploy/pop, data = economics, geom = "line")
qplot(date, uempmed, data = economics, geom = "line")
year <- function(x) as.POSIXlt(x)$year + 1900
qplot(unemploy/pop, uempmed, data = economics, geom = "path", colour = year(date)) +
scale_area()
qplot(carat, data = diamonds, facets = color ~ ., geom = "histogram",
binwidth = 0.1, xlim = c(0, 3))
# ..density..
qplot(carat, ..density.., data = diamonds, facets = color ~ ., geom = "histogram",
binwidth = 0.1, xlim = c(0, 3))
qplot(carat, price/carat, data = dsmall, ylab = expression(frac(price,
carat)), xlab = "Weight (carat)", main = "small diamonds", xlim = c(0.1,
1))
## Warning message: Removed 35 rows containing missing values (geom_point).