Ксения Власова
18/10/14
Элементы ggplot2
ggplot(data = cars, aes(x = speed, y = dist)) + geom_point()
ggplot(data = cars, aes(x = speed, y = dist)) + stat_identity()
ggplot(data = cars, aes(x = speed)) + geom_bar()+ coord_polar()+ theme_bw()
ggplot(data = cars, aes(x = speed, y = dist, color = speed, size = dist)) + geom_point()
mustache <- ggplot(data=PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot()
mustache
mustache + guides(fill=guide_legend
(title=NULL))
mustache+theme (legend.position="none")
mustache + scale_fill_discrete(name="Experimental\nCondition",
breaks=c("ctrl", "trt1", "trt2"),labels=c("Control", "Treatment 1", "Treatment 2"))
mustache + theme(legend.position="top")
Position legend in graph, where x, y is 0,0 (bottom left) to 1,1 (top right)
mustache + theme(legend.justification=c(1,0), legend.position=c(1,0))
mustache + ggtitle("Plant growth")
mustache + ggtitle("Plant growth with\ndifferent treatments") + theme(plot.title = element_text(lineheight=.8, face="bold"))
mustache + theme(plot.background = element_rect(fill = "coral1"))
diamonds <- diamonds[sample(nrow(diamonds), 100), ]
(d <- qplot(carat, price, data=diamonds, shape=cut))
d + scale_shape(solid = TRUE)
d + scale_shape(name="Cut of diamond")
library(reshape2)
sp <- ggplot(tips, aes(x=total_bill, y=tip/total_bill)) + geom_point(shape=1)
sp + facet_wrap( ~ day, ncol=2)
sp + facet_grid(sex ~ day) +
theme(strip.text.x = element_text(size=8, angle=75),
strip.text.y = element_text(size=12, face="bold"),
strip.background = element_rect(colour="red", fill="#CCCCFF"))