r_users_group_1 / diamonds.R

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62``` ```## http://www.statistik.tuwien.ac.at/public/filz/students/seminar/ws1011/bauer_Rcode.R ## this ## install.packages("ggplot2") library(ggplot2) data(diamonds) set.seed(1410) dsmall <- diamonds[sample(nrow(diamonds), 100), ] # create random sample of 100 diamonds qplot(carat, price, data=diamonds) ## qplot(log(carat), log(price), data=diamonds) # log the axes qplot(carat, price, data=diamonds, log="xy") # does the same qplot(carat, price, data=diamonds, alpha=I(1/10)) # makes the points semi-transparent ## Boxplots and jittered points qplot(color, price/carat, data=diamonds, geom="jitter", alpha=I(1/10)) qplot(color, price/carat, data=diamonds, geom="boxplot") ## Histogram and density plots qplot(carat, data=diamonds, geom="histogram", binwidth=0.1) qplot(carat, data=diamonds, geom="density") ## Facets qplot(carat, data=diamonds, facets=color ~., geom="histogram", binwidth=0.1, xlim=c(0,3)) qplot(carat, ..density.., data=diamonds, facets=color ~., geom="histogram", binwidth=0.1, xlim=c(0,3)) ### Layer Examples ######################################################### p <- ggplot(diamonds, aes(carat, price, colour=cut)) # creates plot object p <- p + layer(geom="point") print(p) p <- ggplot(diamonds, aes(x=carat)) # complex example p <- p + layer( geom="bar", geom_params=list(fill="steelblue"), stat="bin", stat_params=list(binwidth = 2)) p p <- ggplot(diamonds, aes(x=carat)) # the same example but simplified p <- p + geom_histogram(binwidth=2, fill="steelblue") p ```