head(mpg)
## [1] 18 15 18 16 17 15
qplot(displ, hwy, data = mpg, colour = factor(cyl))
## Error: ggplot2 doesn't know how to deal with data of class numeric
qplot(displ, hwy, data=mpg, colour=factor(cyl), geom="line")
qplot(displ, hwy, data=mpg, colour=factor(cyl), geom="bar", stat="identity", position = "identity")
# A complex plot without nameqplot(displ, hwy, data=mpg, colour=factor(cyl)) + geom_smooth(data = subset(mpg, cyl != 5), method="lm")
# A more complex plot with facets and multiple layers.qplot(displ, hwy, data=mpg, facets = . ~ year) + geom_smooth()
x <- 1:10y <- factor(letters[1:5])qplot(x, x, size = x)
qplot(x, x, 1:10, colour = x)
qplot(y, y, 1:10, shape = y)
qplot(y, y, 1:10, colour = y)
x1 <- c(1,10)y1 <- c(1, 5)p <- qplot(x1, y1, geom="blank", xlab=NULL, ylab=NULL) + theme_bw()p
p + coord_trans(y="log10")
p + coord_polar()
p <- qplot(displ, hwy, data = mpg, colour = factor(cyl))
summary(p)
## data: [0x0]## mapping: x = x1, y = y1## faceting: facet_null() ## -----------------------------------## geom_blank: ## stat_identity: ## position_identity: (width = NULL, height = NULL)
# Save plot object to disk# save(p, file = "plot.rdata")# Load from disk# load("plot.rdata")# Save png to disk# ggsave("plot.png", width = 5, height = 5)
[trang chủ] [liên hệ] [code]